示例#1
0
 private static void SortMethod(MethodMeta aMethod)
 {
     if (aMethod.Body != null)
     {
         aMethod.Body.ExceptionHandlingClauses = (from item in aMethod.Body.ExceptionHandlingClauses
                                                  orderby item.TryStart,
                                                  item.TryEnd,
                                                  item.Flags,
                                                  item.HandlerStart,
                                                  item.HandlerEnd,
                                                  item.FilterStart,
                                                  item.CatchType
                                                  select item).ToArray();
     }
 }
示例#2
0
 private static void SortMethod(MethodMeta aMethod)
 {
     if (aMethod.Body != null)
     {
         aMethod.Body.ExceptionHandlingClauses = (from item in aMethod.Body.ExceptionHandlingClauses
                                                  orderby item.TryStart,
                                                  item.TryEnd,
                                                  item.Flags,
                                                  item.HandlerStart,
                                                  item.HandlerEnd,
                                                  item.FilterStart,
                                                  item.CatchType
                                                  select item).ToArray();
     }
 }
示例#3
0
文件: Dump.cs 项目: Orvid/Cosmos
        private static void DumpMethod(MethodMeta method, XmlWriter output)
        {
            output.WriteStartElement("Method");
            {
#if DEBUG
                output.WriteAttributeString("MetaId", (string)method.Data[DataIds.DebugMetaId]);
#endif
                //output.WriteAttributeString("FullName", method.Name);
                output.WriteAttributeString("IsStatic", method.IsStatic.ToString());
                output.WriteAttributeString("IsVirtual", method.IsVirtual.ToString());
                output.WriteAttributeString("StartsNewVirtualTree", method.StartsNewVirtualTree.ToString());
#if DEBUG
                if (method.Overrides!=null)
                {
                    output.WriteAttributeString("Overrides", (string)method.Overrides.Data[DataIds.DebugMetaId]);
                }
                if (method.ReturnType != null)
                {
                    output.WriteAttributeString("ReturnType",  (string)method.ReturnType.Data[DataIds.DebugMetaId]);
                }
#endif
                output.WriteStartElement("Parameters");
                {
                    foreach (var xParam in method.Parameters)
                    {
                        DumpParameter(xParam, output);
                    }
                }
                output.WriteEndElement();
                if (method.Body != null)
                {
                    output.WriteStartElement("Body");
                    {
                        #region Locals
                        output.WriteAttributeString("InitLocals", method.Body.InitLocals.ToString());

                        output.WriteStartElement("Locals");
                        {
                            for (int i = 0; i < method.Body.LocalVariables.Length; i++)
                            {
                                output.WriteStartElement("Local");
                                {
                                    output.WriteAttributeString("Index", i.ToString());
#if DEBUG
                                    output.WriteAttributeString("Type", (string)method.Body.LocalVariables[i].Data[EcmaCil.DataIds.DebugMetaId]);
#endif
                                    //output.WriteAttributeString("IsPinned", method.Body.LocalVariables[i].IsPinned.ToString());
                                    //output.WriteAttributeString("LocalType", "#" + method.Body.LocalVariables[i].LocalType.MetaId);
                                }
                                output.WriteEndElement();
                            }
                        }
                        output.WriteEndElement();
                        #endregion
                        #region ExceptionHandlingClauses
                        output.WriteStartElement("ExceptionHandlingClauses");
                        {
                            if (method.Body.ExceptionHandlingClauses != null)
                            {
                                foreach (var xClause in method.Body.ExceptionHandlingClauses)
                                {
                                    output.WriteStartElement("Clause");
                                    {
                                        output.WriteAttributeString("Flags", xClause.Flags.ToString());
                                        output.WriteAttributeString("HandlerStart", xClause.HandlerStart.ToString());
                                        output.WriteAttributeString("HandlerEnd", xClause.HandlerEnd.ToString());
                                        output.WriteAttributeString("TryStart", xClause.TryStart.ToString());
                                        output.WriteAttributeString("TryEnd", xClause.TryEnd.ToString());
                                        output.WriteAttributeString("FilterStart", xClause.FilterStart.ToString());
                                        if (xClause.CatchType != null)
                                        {
                                            //                                        output.WriteAttributeString("CatchType", "#" + xClause.CatchType.MetaId);
                                            output.WriteAttributeString("HasCatchType", "true");
                                        }
                                    }
                                    output.WriteEndElement();
                                }
                            }
                        }
                        output.WriteEndElement();
                        #endregion
                        #region instructions
                        output.WriteStartElement("Instructions");
                        {
                            for (int i = 0; i < method.Body.Instructions.Length; i++)
                            {
                                var xInstruction = method.Body.Instructions[i];
                                output.WriteStartElement("Instruction");
                                {
                                    output.WriteAttributeString("Index", i.ToString());
                                    output.WriteAttributeString("Kind", xInstruction.InstructionKind.ToString());
                                    switch (xInstruction.GetType().Name)
                                    {
                                        case "InstructionNone":
                                            break;
                                        case "InstructionInt32":
                                            var xInstr32 = (InstructionInt32)xInstruction;
                                            output.WriteAttributeString("Value", xInstr32.Value.ToString());
                                            break;
                                        case "InstructionLocal":
                                            var xInstrLocal = (InstructionLocal)xInstruction;
                                            output.WriteAttributeString("LocalIndex", Array.IndexOf<LocalVariableMeta>(method.Body.LocalVariables, xInstrLocal.LocalVariable).ToString());
                                            break;
                                        case "InstructionMethod":
                                            var xInstrMethod = (InstructionMethod)xInstruction;
#if DEBUG
                                            output.WriteAttributeString("Method", (string)xInstrMethod.Value.Data[EcmaCil.DataIds.DebugMetaId]);
#endif
                                            //output.WriteAttributeString("Method", "#" + xInstrMethod.Value.MetaId);
                                            break;
                                        case "InstructionArgument":
                                            var xInstrArg = (InstructionArgument)xInstruction;
#if DEBUG
                                            output.WriteAttributeString("Argument", (string)xInstrArg.Argument.Data[EcmaCil.DataIds.DebugMetaId]);
#endif
                                            break;
                                        case "InstructionBranch":
                                            var xInstrBranch = (InstructionBranch)xInstruction;
                                            output.WriteAttributeString("TargetIdx", xInstrBranch.Target.InstructionIndex.ToString());
                                            break;
                                        case "InstructionType":
                                            var xInstrType = (InstructionType)xInstruction;
                                            //output.WriteAttributeString("Type", xInstrType.Type.MetaId);
                                            break;
                                        case "InstructionField":
                                            var xInstrField = (InstructionField)xInstruction;
                                            //output.WriteAttributeString("Field", xInstrField.Field.Name);
                                            break;
                                        case "InstructionString":
                                            var xInstrString = (InstructionString)xInstruction;
                                            output.WriteAttributeString("LiteralString", xInstrString.LiteralString);
                                            break;
                                        case "InstructionSwitch":
                                            break;
                                        case "InstructionToken":
                                            break;
                                        case "InstructionSingle":
                                            var xInstrSingle = (InstructionSingle)xInstruction;
                                            output.WriteAttributeString("Value", xInstrSingle.Value.ToString());
                                            break;
                                        case "InstructionDouble":
                                            var xInstrDouble = (InstructionDouble)xInstruction;
                                            output.WriteAttributeString("Value", xInstrDouble.Value.ToString());
                                            break;
                                        case "InstructionInt64":
                                            var xInstrInt64 = (InstructionInt64)xInstruction;
                                            output.WriteAttributeString("Value", xInstrInt64.Value.ToString());
                                            break;
                                        default:
                                            throw new NotImplementedException("Instruction kind not implemented: " + xInstruction.GetType().Name);
                                    }
                                }
                                output.WriteEndElement();
                            }
                        }
                        output.WriteEndElement();
                        #endregion
                    }
                    output.WriteEndElement();
                }
            }
            output.WriteEndElement();
        }
示例#4
0
文件: Dump.cs 项目: zer09/Cosmos
        private static void DumpMethod(MethodMeta method, XmlWriter output)
        {
            output.WriteStartElement("Method");
            {
#if DEBUG
                output.WriteAttributeString("MetaId", (string)method.Data[DataIds.DebugMetaId]);
#endif
                //output.WriteAttributeString("FullName", method.Name);
                output.WriteAttributeString("IsStatic", method.IsStatic.ToString());
                output.WriteAttributeString("IsVirtual", method.IsVirtual.ToString());
                output.WriteAttributeString("StartsNewVirtualTree", method.StartsNewVirtualTree.ToString());
#if DEBUG
                if (method.Overrides != null)
                {
                    output.WriteAttributeString("Overrides", (string)method.Overrides.Data[DataIds.DebugMetaId]);
                }
                if (method.ReturnType != null)
                {
                    output.WriteAttributeString("ReturnType", (string)method.ReturnType.Data[DataIds.DebugMetaId]);
                }
#endif
                output.WriteStartElement("Parameters");
                {
                    foreach (var xParam in method.Parameters)
                    {
                        DumpParameter(xParam, output);
                    }
                }
                output.WriteEndElement();
                if (method.Body != null)
                {
                    output.WriteStartElement("Body");
                    {
                        #region Locals
                        output.WriteAttributeString("InitLocals", method.Body.InitLocals.ToString());

                        output.WriteStartElement("Locals");
                        {
                            for (int i = 0; i < method.Body.LocalVariables.Length; i++)
                            {
                                output.WriteStartElement("Local");
                                {
                                    output.WriteAttributeString("Index", i.ToString());
#if DEBUG
                                    output.WriteAttributeString("Type", (string)method.Body.LocalVariables[i].Data[EcmaCil.DataIds.DebugMetaId]);
#endif
                                    //output.WriteAttributeString("IsPinned", method.Body.LocalVariables[i].IsPinned.ToString());
                                    //output.WriteAttributeString("LocalType", "#" + method.Body.LocalVariables[i].LocalType.MetaId);
                                }
                                output.WriteEndElement();
                            }
                        }
                        output.WriteEndElement();
                        #endregion
                        #region ExceptionHandlingClauses
                        output.WriteStartElement("ExceptionHandlingClauses");
                        {
                            if (method.Body.ExceptionHandlingClauses != null)
                            {
                                foreach (var xClause in method.Body.ExceptionHandlingClauses)
                                {
                                    output.WriteStartElement("Clause");
                                    {
                                        output.WriteAttributeString("Flags", xClause.Flags.ToString());
                                        output.WriteAttributeString("HandlerStart", xClause.HandlerStart.ToString());
                                        output.WriteAttributeString("HandlerEnd", xClause.HandlerEnd.ToString());
                                        output.WriteAttributeString("TryStart", xClause.TryStart.ToString());
                                        output.WriteAttributeString("TryEnd", xClause.TryEnd.ToString());
                                        output.WriteAttributeString("FilterStart", xClause.FilterStart.ToString());
                                        if (xClause.CatchType != null)
                                        {
                                            //                                        output.WriteAttributeString("CatchType", "#" + xClause.CatchType.MetaId);
                                            output.WriteAttributeString("HasCatchType", "true");
                                        }
                                    }
                                    output.WriteEndElement();
                                }
                            }
                        }
                        output.WriteEndElement();
                        #endregion
                        #region instructions
                        output.WriteStartElement("Instructions");
                        {
                            for (int i = 0; i < method.Body.Instructions.Length; i++)
                            {
                                var xInstruction = method.Body.Instructions[i];
                                output.WriteStartElement("Instruction");
                                {
                                    output.WriteAttributeString("Index", i.ToString());
                                    output.WriteAttributeString("Kind", xInstruction.InstructionKind.ToString());
                                    switch (xInstruction.GetType().Name)
                                    {
                                    case "InstructionNone":
                                        break;

                                    case "InstructionInt32":
                                        var xInstr32 = (InstructionInt32)xInstruction;
                                        output.WriteAttributeString("Value", xInstr32.Value.ToString());
                                        break;

                                    case "InstructionLocal":
                                        var xInstrLocal = (InstructionLocal)xInstruction;
                                        output.WriteAttributeString("LocalIndex", Array.IndexOf <LocalVariableMeta>(method.Body.LocalVariables, xInstrLocal.LocalVariable).ToString());
                                        break;

                                    case "InstructionMethod":
                                        var xInstrMethod = (InstructionMethod)xInstruction;
#if DEBUG
                                        output.WriteAttributeString("Method", (string)xInstrMethod.Value.Data[EcmaCil.DataIds.DebugMetaId]);
#endif
                                        //output.WriteAttributeString("Method", "#" + xInstrMethod.Value.MetaId);
                                        break;

                                    case "InstructionArgument":
                                        var xInstrArg = (InstructionArgument)xInstruction;
#if DEBUG
                                        output.WriteAttributeString("Argument", (string)xInstrArg.Argument.Data[EcmaCil.DataIds.DebugMetaId]);
#endif
                                        break;

                                    case "InstructionBranch":
                                        var xInstrBranch = (InstructionBranch)xInstruction;
                                        output.WriteAttributeString("TargetIdx", xInstrBranch.Target.InstructionIndex.ToString());
                                        break;

                                    case "InstructionType":
                                        var xInstrType = (InstructionType)xInstruction;
                                        //output.WriteAttributeString("Type", xInstrType.Type.MetaId);
                                        break;

                                    case "InstructionField":
                                        var xInstrField = (InstructionField)xInstruction;
                                        //output.WriteAttributeString("Field", xInstrField.Field.Name);
                                        break;

                                    case "InstructionString":
                                        var xInstrString = (InstructionString)xInstruction;
                                        output.WriteAttributeString("LiteralString", xInstrString.LiteralString);
                                        break;

                                    case "InstructionSwitch":
                                        break;

                                    case "InstructionToken":
                                        break;

                                    case "InstructionSingle":
                                        var xInstrSingle = (InstructionSingle)xInstruction;
                                        output.WriteAttributeString("Value", xInstrSingle.Value.ToString());
                                        break;

                                    case "InstructionDouble":
                                        var xInstrDouble = (InstructionDouble)xInstruction;
                                        output.WriteAttributeString("Value", xInstrDouble.Value.ToString());
                                        break;

                                    case "InstructionInt64":
                                        var xInstrInt64 = (InstructionInt64)xInstruction;
                                        output.WriteAttributeString("Value", xInstrInt64.Value.ToString());
                                        break;

                                    default:
                                        throw new NotImplementedException("Instruction kind not implemented: " + xInstruction.GetType().Name);
                                    }
                                }
                                output.WriteEndElement();
                            }
                        }
                        output.WriteEndElement();
                        #endregion
                    }
                    output.WriteEndElement();
                }
            }
            output.WriteEndElement();
        }