Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
//
// BaseCodeVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal abstract class BaseCodeVisitor : ICodeVisitor {
public virtual void VisitMethodBody (MethodBody body)
{
}
public virtual void VisitInstructionCollection (InstructionCollection instructions)
{
}
public virtual void VisitInstruction (Instruction instr)
{
}
public virtual void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh)
{
}
public virtual void VisitExceptionHandler (ExceptionHandler eh)
{
}
public virtual void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
{
}
public virtual void VisitVariableDefinition (VariableDefinition var)
{
}
public virtual void VisitScopeCollection (ScopeCollection scopes)
{
}
public virtual void VisitScope (Scope s)
{
}
public virtual void TerminateMethodBody (MethodBody body)
{
}
}
}

View File

@@ -0,0 +1,402 @@
//
// CilWorker.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using SR = System.Reflection;
internal sealed class CilWorker {
MethodBody m_mbody;
InstructionCollection m_instrs;
internal CilWorker (MethodBody body)
{
m_mbody = body;
m_instrs = m_mbody.Instructions;
}
public MethodBody GetBody ()
{
return m_mbody;
}
public Instruction Create (OpCode opcode)
{
if (opcode.OperandType != OperandType.InlineNone)
throw new ArgumentException ("opcode");
return FinalCreate (opcode);
}
public Instruction Create (OpCode opcode, TypeReference type)
{
if (type == null)
throw new ArgumentNullException ("type");
if (opcode.OperandType != OperandType.InlineType &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, type);
}
public Instruction Create (OpCode opcode, CallSite site)
{
if (site == null)
throw new ArgumentNullException ("site");
if (opcode.Code != Code.Calli)
throw new ArgumentException ("code");
return FinalCreate (opcode, site);
}
public Instruction Create (OpCode opcode, MethodReference method)
{
if (method == null)
throw new ArgumentNullException ("method");
if (opcode.OperandType != OperandType.InlineMethod &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, method);
}
public Instruction Create (OpCode opcode, FieldReference field)
{
if (field == null)
throw new ArgumentNullException ("field");
if (opcode.OperandType != OperandType.InlineField &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, field);
}
public Instruction Create (OpCode opcode, string str)
{
if (str == null)
throw new ArgumentNullException ("str");
if (opcode.OperandType != OperandType.InlineString)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, str);
}
public Instruction Create (OpCode opcode, sbyte b)
{
if (opcode.OperandType != OperandType.ShortInlineI &&
opcode != OpCodes.Ldc_I4_S)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, b);
}
public Instruction Create (OpCode opcode, byte b)
{
if (opcode.OperandType == OperandType.ShortInlineVar)
return Create (opcode, m_mbody.Variables [b]);
if (opcode.OperandType == OperandType.ShortInlineParam)
return Create (opcode, CodeReader.GetParameter (m_mbody, b));
if (opcode.OperandType != OperandType.ShortInlineI ||
opcode == OpCodes.Ldc_I4_S)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, b);
}
public Instruction Create (OpCode opcode, int i)
{
if (opcode.OperandType == OperandType.InlineVar)
return Create (opcode, m_mbody.Variables [i]);
if (opcode.OperandType == OperandType.InlineParam)
return Create (opcode, CodeReader.GetParameter (m_mbody, i));
if (opcode.OperandType != OperandType.InlineI)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, i);
}
public Instruction Create (OpCode opcode, long l)
{
if (opcode.OperandType != OperandType.InlineI8)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, l);
}
public Instruction Create (OpCode opcode, float f)
{
if (opcode.OperandType != OperandType.ShortInlineR)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, f);
}
public Instruction Create (OpCode opcode, double d)
{
if (opcode.OperandType != OperandType.InlineR)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, d);
}
public Instruction Create (OpCode opcode, Instruction label)
{
if (label == null)
throw new ArgumentNullException ("label");
if (opcode.OperandType != OperandType.InlineBrTarget &&
opcode.OperandType != OperandType.ShortInlineBrTarget)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, label);
}
public Instruction Create (OpCode opcode, Instruction [] labels)
{
if (labels == null)
throw new ArgumentNullException ("labels");
if (opcode.OperandType != OperandType.InlineSwitch)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, labels);
}
public Instruction Create (OpCode opcode, VariableDefinition var)
{
if (var == null)
throw new ArgumentNullException ("var");
if (opcode.OperandType != OperandType.ShortInlineVar &&
opcode.OperandType != OperandType.InlineVar)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, var);
}
public Instruction Create (OpCode opcode, ParameterDefinition param)
{
if (param == null)
throw new ArgumentNullException ("param");
if (opcode.OperandType != OperandType.ShortInlineParam &&
opcode.OperandType != OperandType.InlineParam)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, param);
}
static Instruction FinalCreate (OpCode opcode)
{
return FinalCreate (opcode, null);
}
static Instruction FinalCreate (OpCode opcode, object operand)
{
return new Instruction (opcode, operand);
}
public Instruction Emit (OpCode opcode)
{
Instruction instr = Create (opcode);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, TypeReference type)
{
Instruction instr = Create (opcode, type);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, MethodReference meth)
{
Instruction instr = Create (opcode, meth);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, CallSite site)
{
Instruction instr = Create (opcode, site);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, FieldReference field)
{
Instruction instr = Create (opcode, field);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, string str)
{
Instruction instr = Create (opcode, str);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, byte b)
{
Instruction instr = Create (opcode, b);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, sbyte b)
{
Instruction instr = Create (opcode, b);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, int i)
{
Instruction instr = Create (opcode, i);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, long l)
{
Instruction instr = Create (opcode, l);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, float f)
{
Instruction instr = Create (opcode, f);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, double d)
{
Instruction instr = Create (opcode, d);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, Instruction target)
{
Instruction instr = Create (opcode, target);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, Instruction [] targets)
{
Instruction instr = Create (opcode, targets);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, VariableDefinition var)
{
Instruction instr = Create (opcode, var);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, ParameterDefinition param)
{
Instruction instr = Create (opcode, param);
Append (instr);
return instr;
}
public void InsertBefore (Instruction target, Instruction instr)
{
int index = m_instrs.IndexOf (target);
if (index == -1)
throw new ArgumentOutOfRangeException ("Target instruction not in method body");
m_instrs.Insert (index, instr);
instr.Previous = target.Previous;
if (target.Previous != null)
target.Previous.Next = instr;
target.Previous = instr;
instr.Next = target;
}
public void InsertAfter (Instruction target, Instruction instr)
{
int index = m_instrs.IndexOf (target);
if (index == -1)
throw new ArgumentOutOfRangeException ("Target instruction not in method body");
m_instrs.Insert (index + 1, instr);
instr.Next = target.Next;
if (target.Next != null)
target.Next.Previous = instr;
target.Next = instr;
instr.Previous = target;
}
public void Append (Instruction instr)
{
Instruction last = null, current = instr;
if (m_instrs.Count > 0)
last = m_instrs [m_instrs.Count - 1];
if (last != null) {
last.Next = instr;
current.Previous = last;
}
m_instrs.Add (current);
}
public void Replace (Instruction old, Instruction instr)
{
int index = m_instrs.IndexOf (old);
if (index == -1)
throw new ArgumentOutOfRangeException ("Target instruction not in method body");
InsertAfter (old, instr);
Remove (old);
}
public void Remove (Instruction instr)
{
if (!m_instrs.Contains (instr))
throw new ArgumentException ("Instruction not in method body");
if (instr.Previous != null)
instr.Previous.Next = instr.Next;
if (instr.Next != null)
instr.Next.Previous = instr.Previous;
m_instrs.Remove (instr);
}
}
}

View File

@@ -0,0 +1,255 @@
//
// Code.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// Fri Mar 16 15:37:23 +0100 2007
//
// (C) 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal enum Code {
Nop,
Break,
Ldarg_0,
Ldarg_1,
Ldarg_2,
Ldarg_3,
Ldloc_0,
Ldloc_1,
Ldloc_2,
Ldloc_3,
Stloc_0,
Stloc_1,
Stloc_2,
Stloc_3,
Ldarg_S,
Ldarga_S,
Starg_S,
Ldloc_S,
Ldloca_S,
Stloc_S,
Ldnull,
Ldc_I4_M1,
Ldc_I4_0,
Ldc_I4_1,
Ldc_I4_2,
Ldc_I4_3,
Ldc_I4_4,
Ldc_I4_5,
Ldc_I4_6,
Ldc_I4_7,
Ldc_I4_8,
Ldc_I4_S,
Ldc_I4,
Ldc_I8,
Ldc_R4,
Ldc_R8,
Dup,
Pop,
Jmp,
Call,
Calli,
Ret,
Br_S,
Brfalse_S,
Brtrue_S,
Beq_S,
Bge_S,
Bgt_S,
Ble_S,
Blt_S,
Bne_Un_S,
Bge_Un_S,
Bgt_Un_S,
Ble_Un_S,
Blt_Un_S,
Br,
Brfalse,
Brtrue,
Beq,
Bge,
Bgt,
Ble,
Blt,
Bne_Un,
Bge_Un,
Bgt_Un,
Ble_Un,
Blt_Un,
Switch,
Ldind_I1,
Ldind_U1,
Ldind_I2,
Ldind_U2,
Ldind_I4,
Ldind_U4,
Ldind_I8,
Ldind_I,
Ldind_R4,
Ldind_R8,
Ldind_Ref,
Stind_Ref,
Stind_I1,
Stind_I2,
Stind_I4,
Stind_I8,
Stind_R4,
Stind_R8,
Add,
Sub,
Mul,
Div,
Div_Un,
Rem,
Rem_Un,
And,
Or,
Xor,
Shl,
Shr,
Shr_Un,
Neg,
Not,
Conv_I1,
Conv_I2,
Conv_I4,
Conv_I8,
Conv_R4,
Conv_R8,
Conv_U4,
Conv_U8,
Callvirt,
Cpobj,
Ldobj,
Ldstr,
Newobj,
Castclass,
Isinst,
Conv_R_Un,
Unbox,
Throw,
Ldfld,
Ldflda,
Stfld,
Ldsfld,
Ldsflda,
Stsfld,
Stobj,
Conv_Ovf_I1_Un,
Conv_Ovf_I2_Un,
Conv_Ovf_I4_Un,
Conv_Ovf_I8_Un,
Conv_Ovf_U1_Un,
Conv_Ovf_U2_Un,
Conv_Ovf_U4_Un,
Conv_Ovf_U8_Un,
Conv_Ovf_I_Un,
Conv_Ovf_U_Un,
Box,
Newarr,
Ldlen,
Ldelema,
Ldelem_I1,
Ldelem_U1,
Ldelem_I2,
Ldelem_U2,
Ldelem_I4,
Ldelem_U4,
Ldelem_I8,
Ldelem_I,
Ldelem_R4,
Ldelem_R8,
Ldelem_Ref,
Stelem_I,
Stelem_I1,
Stelem_I2,
Stelem_I4,
Stelem_I8,
Stelem_R4,
Stelem_R8,
Stelem_Ref,
Ldelem_Any,
Stelem_Any,
Unbox_Any,
Conv_Ovf_I1,
Conv_Ovf_U1,
Conv_Ovf_I2,
Conv_Ovf_U2,
Conv_Ovf_I4,
Conv_Ovf_U4,
Conv_Ovf_I8,
Conv_Ovf_U8,
Refanyval,
Ckfinite,
Mkrefany,
Ldtoken,
Conv_U2,
Conv_U1,
Conv_I,
Conv_Ovf_I,
Conv_Ovf_U,
Add_Ovf,
Add_Ovf_Un,
Mul_Ovf,
Mul_Ovf_Un,
Sub_Ovf,
Sub_Ovf_Un,
Endfinally,
Leave,
Leave_S,
Stind_I,
Conv_U,
Arglist,
Ceq,
Cgt,
Cgt_Un,
Clt,
Clt_Un,
Ldftn,
Ldvirtftn,
Ldarg,
Ldarga,
Starg,
Ldloc,
Ldloca,
Stloc,
Localloc,
Endfilter,
Unaligned,
Volatile,
Tail,
Initobj,
Constrained,
Cpblk,
Initblk,
No,
Rethrow,
Sizeof,
Refanytype,
Readonly,
}
}

View File

@@ -0,0 +1,361 @@
//
// CodeReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using System.Collections;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Metadata;
using Mono.Cecil.Signatures;
sealed class CodeReader : BaseCodeVisitor {
ReflectionReader m_reflectReader;
MetadataRoot m_root;
IDictionary m_instructions;
public CodeReader (ReflectionReader reflectReader)
{
m_reflectReader = reflectReader;
m_root = m_reflectReader.MetadataRoot;
m_instructions = new Hashtable ();
}
public override void VisitMethodBody (MethodBody body)
{
MethodDefinition meth = body.Method;
MethodBody methBody = body;
BinaryReader br = m_reflectReader.Module.ImageReader.MetadataReader.GetDataReader (meth.RVA);
// lets read the method
int flags = br.ReadByte ();
switch (flags & 0x3) {
case (int) MethodHeader.TinyFormat :
methBody.CodeSize = flags >> 2;
methBody.MaxStack = 8;
ReadCilBody (methBody, br);
break;
case (int) MethodHeader.FatFormat :
br.BaseStream.Position--;
int fatflags = br.ReadUInt16 ();
//int headersize = (fatflags >> 12) & 0xf;
methBody.MaxStack = br.ReadUInt16 ();
methBody.CodeSize = br.ReadInt32 ();
methBody.LocalVarToken = br.ReadInt32 ();
body.InitLocals = (fatflags & (int) MethodHeader.InitLocals) != 0;
if (methBody.LocalVarToken != 0)
VisitVariableDefinitionCollection (methBody.Variables);
ReadCilBody (methBody, br);
if ((fatflags & (int) MethodHeader.MoreSects) != 0)
ReadSection (methBody, br);
break;
}
}
public static uint GetRid (int token)
{
return (uint) token & 0x00ffffff;
}
public static ParameterDefinition GetParameter (MethodBody body, int index)
{
if (body.Method.HasThis) {
if (index == 0)
return body.Method.This;
index--;
}
return body.Method.Parameters [index];
}
public static VariableDefinition GetVariable (MethodBody body, int index)
{
// bug 15727 - newer cecil does the same (in MethodDefinition.GetVariable)
var variables = body.Variables;
if (index < 0 || index >= variables.Count)
return null;
return variables [index];
}
void ReadCilBody (MethodBody body, BinaryReader br)
{
long start = br.BaseStream.Position;
Instruction last = null;
m_instructions.Clear();
InstructionCollection code = body.Instructions;
GenericContext context = new GenericContext (body.Method);
while (br.BaseStream.Position < start + body.CodeSize) {
OpCode op;
long offset = br.BaseStream.Position - start;
int cursor = br.ReadByte ();
if (cursor == 0xfe)
op = OpCodes.TwoBytesOpCode [br.ReadByte ()];
else
op = OpCodes.OneByteOpCode [cursor];
Instruction instr = new Instruction ((int) offset, op);
switch (op.OperandType) {
case OperandType.InlineNone :
break;
case OperandType.InlineSwitch :
uint length = br.ReadUInt32 ();
int [] branches = new int [length];
int [] buf = new int [length];
for (int i = 0; i < length; i++)
buf [i] = br.ReadInt32 ();
for (int i = 0; i < length; i++)
branches [i] = Convert.ToInt32 (br.BaseStream.Position - start + buf [i]);
instr.Operand = branches;
break;
case OperandType.ShortInlineBrTarget :
sbyte sbrtgt = br.ReadSByte ();
instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + sbrtgt);
break;
case OperandType.InlineBrTarget :
int brtgt = br.ReadInt32 ();
instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + brtgt);
break;
case OperandType.ShortInlineI :
if (op == OpCodes.Ldc_I4_S)
instr.Operand = br.ReadSByte ();
else
instr.Operand = br.ReadByte ();
break;
case OperandType.ShortInlineVar :
instr.Operand = GetVariable (body, br.ReadByte ());
break;
case OperandType.ShortInlineParam :
instr.Operand = GetParameter (body, br.ReadByte ());
break;
case OperandType.InlineSig :
instr.Operand = GetCallSiteAt (br.ReadInt32 (), context);
break;
case OperandType.InlineI :
instr.Operand = br.ReadInt32 ();
break;
case OperandType.InlineVar :
instr.Operand = GetVariable (body, br.ReadInt16 ());
break;
case OperandType.InlineParam :
instr.Operand = GetParameter (body, br.ReadInt16 ());
break;
case OperandType.InlineI8 :
instr.Operand = br.ReadInt64 ();
break;
case OperandType.ShortInlineR :
instr.Operand = br.ReadSingle ();
break;
case OperandType.InlineR :
instr.Operand = br.ReadDouble ();
break;
case OperandType.InlineString :
instr.Operand = m_root.Streams.UserStringsHeap [GetRid (br.ReadInt32 ())];
break;
case OperandType.InlineField :
case OperandType.InlineMethod :
case OperandType.InlineType :
case OperandType.InlineTok :
MetadataToken token = new MetadataToken (br.ReadInt32 ());
switch (token.TokenType) {
case TokenType.TypeDef:
instr.Operand = m_reflectReader.GetTypeDefAt (token.RID);
break;
case TokenType.TypeRef:
instr.Operand = m_reflectReader.GetTypeRefAt (token.RID);
break;
case TokenType.TypeSpec:
instr.Operand = m_reflectReader.GetTypeSpecAt (token.RID, context);
break;
case TokenType.Field:
instr.Operand = m_reflectReader.GetFieldDefAt (token.RID);
break;
case TokenType.Method:
instr.Operand = m_reflectReader.GetMethodDefAt (token.RID);
break;
case TokenType.MethodSpec:
instr.Operand = m_reflectReader.GetMethodSpecAt (token.RID, context);
break;
case TokenType.MemberRef:
instr.Operand = m_reflectReader.GetMemberRefAt (token.RID, context);
break;
default:
throw new ReflectionException ("Wrong token: " + token);
}
break;
}
m_instructions.Add (instr.Offset, instr);
if (last != null) {
last.Next = instr;
instr.Previous = last;
}
last = instr;
code.Add (instr);
}
// resolve branches
foreach (Instruction i in code) {
switch (i.OpCode.OperandType) {
case OperandType.ShortInlineBrTarget:
case OperandType.InlineBrTarget:
i.Operand = GetInstruction (body, (int) i.Operand);
break;
case OperandType.InlineSwitch:
int [] lbls = (int []) i.Operand;
Instruction [] instrs = new Instruction [lbls.Length];
for (int j = 0; j < lbls.Length; j++)
instrs [j] = GetInstruction (body, lbls [j]);
i.Operand = instrs;
break;
}
}
if (m_reflectReader.SymbolReader != null)
m_reflectReader.SymbolReader.Read (body, m_instructions);
}
Instruction GetInstruction (MethodBody body, int offset)
{
Instruction instruction = m_instructions [offset] as Instruction;
if (instruction != null)
return instruction;
return body.Instructions.Outside;
}
void ReadSection (MethodBody body, BinaryReader br)
{
br.BaseStream.Position += 3;
br.BaseStream.Position &= ~3;
byte flags = br.ReadByte ();
if ((flags & (byte) MethodDataSection.FatFormat) == 0) {
int length = br.ReadByte () / 12;
br.ReadBytes (2);
for (int i = 0; i < length; i++) {
ExceptionHandler eh = new ExceptionHandler (
(ExceptionHandlerType) (br.ReadInt16 () & 0x7));
eh.TryStart = GetInstruction (body, Convert.ToInt32 (br.ReadInt16 ()));
eh.TryEnd = GetInstruction (body, eh.TryStart.Offset + Convert.ToInt32 (br.ReadByte ()));
eh.HandlerStart = GetInstruction (body, Convert.ToInt32 (br.ReadInt16 ()));
eh.HandlerEnd = GetInstruction (body, eh.HandlerStart.Offset + Convert.ToInt32 (br.ReadByte ()));
ReadExceptionHandlerEnd (eh, br, body);
body.ExceptionHandlers.Add (eh);
}
} else {
br.BaseStream.Position--;
int length = (br.ReadInt32 () >> 8) / 24;
if ((flags & (int) MethodDataSection.EHTable) == 0)
br.ReadBytes (length * 24);
for (int i = 0; i < length; i++) {
ExceptionHandler eh = new ExceptionHandler (
(ExceptionHandlerType) (br.ReadInt32 () & 0x7));
eh.TryStart = GetInstruction (body, br.ReadInt32 ());
eh.TryEnd = GetInstruction (body, eh.TryStart.Offset + br.ReadInt32 ());
eh.HandlerStart = GetInstruction (body, br.ReadInt32 ());
eh.HandlerEnd = GetInstruction (body, eh.HandlerStart.Offset + br.ReadInt32 ());
ReadExceptionHandlerEnd (eh, br, body);
body.ExceptionHandlers.Add (eh);
}
}
if ((flags & (byte) MethodDataSection.MoreSects) != 0)
ReadSection (body, br);
}
void ReadExceptionHandlerEnd (ExceptionHandler eh, BinaryReader br, MethodBody body)
{
switch (eh.Type) {
case ExceptionHandlerType.Catch :
MetadataToken token = new MetadataToken (br.ReadInt32 ());
eh.CatchType = m_reflectReader.GetTypeDefOrRef (token, new GenericContext (body.Method));
break;
case ExceptionHandlerType.Filter :
eh.FilterStart = GetInstruction (body, br.ReadInt32 ());
eh.FilterEnd = GetInstruction (body, eh.HandlerStart.Previous.Offset);
break;
default :
br.ReadInt32 ();
break;
}
}
CallSite GetCallSiteAt (int token, GenericContext context)
{
StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable ();
MethodSig ms = m_reflectReader.SigReader.GetStandAloneMethodSig (
sasTable [(int) GetRid (token) - 1].Signature);
CallSite cs = new CallSite (ms.HasThis, ms.ExplicitThis,
ms.MethCallConv, m_reflectReader.GetMethodReturnType (ms, context));
cs.MetadataToken = new MetadataToken (token);
for (int i = 0; i < ms.ParamCount; i++) {
Param p = ms.Parameters [i];
cs.Parameters.Add (m_reflectReader.BuildParameterDefinition (i, p, context));
}
ReflectionReader.CreateSentinelIfNeeded (cs, ms);
return cs;
}
public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
{
MethodBody body = variables.Container as MethodBody;
if (body == null || body.LocalVarToken == 0)
return;
StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable ();
StandAloneSigRow sasRow = sasTable [(int) GetRid (body.LocalVarToken) - 1];
LocalVarSig sig = m_reflectReader.SigReader.GetLocalVarSig (sasRow.Signature);
for (int i = 0; i < sig.Count; i++) {
LocalVarSig.LocalVariable lv = sig.LocalVariables [i];
TypeReference varType = m_reflectReader.GetTypeRefFromSig (
lv.Type, new GenericContext (body.Method));
if (lv.ByRef)
varType = new ReferenceType (varType);
if ((lv.Constraint & Constraint.Pinned) != 0)
varType = new PinnedType (varType);
varType = m_reflectReader.GetModifierType (lv.CustomMods, varType);
body.Variables.Add (new VariableDefinition (
string.Concat ("V_", i), i, body.Method, varType));
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
//
// Document.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
internal class Document {
string m_url;
Guid m_type;
DocumentHashAlgorithm m_hashAlgorithm;
Guid m_language;
Guid m_languageVendor;
byte [] m_hash;
public string Url {
get { return m_url; }
set { m_url = value; }
}
public Guid Type {
get { return m_type; }
set { m_type = value; }
}
public DocumentHashAlgorithm HashAlgorithm {
get { return m_hashAlgorithm; }
set { m_hashAlgorithm = value; }
}
public Guid Language {
get { return m_language; }
set { m_language = value; }
}
public Guid LanguageVendor {
get { return m_languageVendor; }
set { m_languageVendor = value; }
}
public byte [] Hash {
get { return m_hash; }
set { m_hash = value; }
}
public Document (string url)
{
m_url = url;
m_hash = new byte [0];
}
}
}

View File

@@ -0,0 +1,36 @@
//
// DocumentHashAlgorithm.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal enum DocumentHashAlgorithm {
[Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)] None,
[Guid (0x406ea660, 0x64cf, 0x4c82, 0xb6, 0xf0, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99)] MD5,
[Guid (0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60)] SHA1
}
}

View File

@@ -0,0 +1,62 @@
//
// DocumentLanguage.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
internal abstract class DocumentLanguage {
#if CF_2_0
public static readonly Guid None = new Guid ("00000000-0000-0000-0000-000000000000");
public static readonly Guid C = new Guid ("63a08714-fc37-11d2-904c-00c04fa302a1");
public static readonly Guid Cpp = new Guid ("3a12d0b7-c26c-11d0-b442-00a0244a1dd2");
public static readonly Guid CSharp = new Guid ("3f5162f8-07c6-11d3-9053-00c04fa302a1");
public static readonly Guid Basic = new Guid ("3a12d0b8-c26c-11d0-b442-00a0244a1dd2");
public static readonly Guid Java = new Guid ("3a12d0b4-c26c-11d0-b442-00a0244a1dd2");
public static readonly Guid Cobol = new Guid ("af046cd1-d0e1-11d2-977c-00a0c9b4d50c");
public static readonly Guid Pascal = new Guid ("af046cd2-d0e1-11d2-977c-00a0c9b4d50c");
public static readonly Guid CIL = new Guid ("af046cd3-d0e1-11d2-977c-00a0c9b4d50c");
public static readonly Guid JScript = new Guid ("3a12d0b6-c26c-11d0-b442-00a0244a1dd2");
public static readonly Guid SMC = new Guid ("0d9b9f7b-6611-11d3-bd2a-0000f80849bd");
public static readonly Guid MCpp = new Guid ("4b35fde8-07c6-11d3-9053-00c04fa302a1");
#else
public static readonly Guid None = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00);
public static readonly Guid C = new Guid (0x63a08714, 0xfc37, 0x11d2, 0x90, 0x4c, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
public static readonly Guid Cpp = new Guid (0x3a12d0b7, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2);
public static readonly Guid CSharp = new Guid (0x3f5162f8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
public static readonly Guid Basic = new Guid (0x3a12d0b8, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2);
public static readonly Guid Java = new Guid (0x3a12d0b4, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2);
public static readonly Guid Cobol = new Guid (0xaf046cd1, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc);
public static readonly Guid Pascal = new Guid (0xaf046cd2, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc);
public static readonly Guid CIL = new Guid (0xaf046cd3, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc);
public static readonly Guid JScript = new Guid (0x3a12d0b6, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2);
public static readonly Guid SMC = new Guid (0xd9b9f7b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x0, 0x0, 0xf8, 0x8, 0x49, 0xbd);
public static readonly Guid MCpp = new Guid (0x4b35fde8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
#endif
}
}

View File

@@ -0,0 +1,42 @@
//
// DocumentLanguageVendor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
internal abstract class DocumentLanguageVendor {
#if CF_2_0
public static readonly Guid Other = new Guid ("00000000-0000-0000-0000-000000000000");
public static readonly Guid Microsoft = new Guid ("994b45c4-e6e9-11d2-903f-00c04fa302a1");
#else
public static readonly Guid Other = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
public static readonly Guid Microsoft = new Guid (0x994b45c4, 0xe6e9, 0x11d2, 0x90, 0x3f, 0x00, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
#endif
}
}

View File

@@ -0,0 +1,38 @@
//
// DocumentType.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
internal abstract class DocumentType {
public static readonly Guid Other = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
public static readonly Guid Text = new Guid (0x5a869d0b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x00, 0x00, 0xf8, 0x08, 0x49, 0xbd);
}
}

View File

@@ -0,0 +1,95 @@
//
// ExceptionHandler.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using Mono.Cecil;
internal sealed class ExceptionHandler : ICodeVisitable {
Instruction m_tryStart;
Instruction m_tryEnd;
Instruction m_filterStart;
Instruction m_filterEnd;
Instruction m_handlerStart;
Instruction m_handlerEnd;
TypeReference m_catchType;
ExceptionHandlerType m_type;
public Instruction TryStart {
get { return m_tryStart; }
set { m_tryStart = value; }
}
public Instruction TryEnd {
get { return m_tryEnd; }
set { m_tryEnd = value; }
}
public Instruction FilterStart {
get { return m_filterStart; }
set { m_filterStart = value; }
}
public Instruction FilterEnd {
get { return m_filterEnd; }
set { m_filterEnd = value; }
}
public Instruction HandlerStart {
get { return m_handlerStart; }
set { m_handlerStart = value; }
}
public Instruction HandlerEnd {
get { return m_handlerEnd; }
set { m_handlerEnd = value; }
}
public TypeReference CatchType {
get { return m_catchType; }
set { m_catchType = value; }
}
public ExceptionHandlerType Type {
get { return m_type; }
set { m_type = value; }
}
public ExceptionHandler (ExceptionHandlerType type)
{
m_type = type;
}
public void Accept (ICodeVisitor visitor)
{
visitor.VisitExceptionHandler (this);
}
}
}

View File

@@ -0,0 +1,93 @@
//
// ExceptionHandlerCollection.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// Wed Sep 27 12:46:53 CEST 2006
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using System.Collections;
using Mono.Cecil.Cil;
internal sealed class ExceptionHandlerCollection : CollectionBase, ICodeVisitable {
MethodBody m_container;
public ExceptionHandler this [int index] {
get { return List [index] as ExceptionHandler; }
set { List [index] = value; }
}
public MethodBody Container {
get { return m_container; }
}
public ExceptionHandlerCollection (MethodBody container)
{
m_container = container;
}
public void Add (ExceptionHandler value)
{
List.Add (value);
}
public bool Contains (ExceptionHandler value)
{
return List.Contains (value);
}
public int IndexOf (ExceptionHandler value)
{
return List.IndexOf (value);
}
public void Insert (int index, ExceptionHandler value)
{
List.Insert (index, value);
}
public void Remove (ExceptionHandler value)
{
List.Remove (value);
}
protected override void OnValidate (object o)
{
if (! (o is ExceptionHandler))
throw new ArgumentException ("Must be of type " + typeof (ExceptionHandler).FullName);
}
public void Accept (ICodeVisitor visitor)
{
visitor.VisitExceptionHandlerCollection (this);
}
}
}

View File

@@ -0,0 +1,37 @@
//
// ExceptionHandlerType.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal enum ExceptionHandlerType {
Catch = 0x0000,
Filter = 0x0001,
Finally = 0x0002,
Fault = 0x0004
}
}

View File

@@ -0,0 +1,42 @@
//
// FlowControl.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal enum FlowControl {
Branch,
Break,
Call,
Cond_Branch,
Meta,
Next,
Phi,
Return,
Throw
}
}

View File

@@ -0,0 +1,91 @@
//
// GuidAttribute.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using System.Reflection;
[AttributeUsage (AttributeTargets.Field)]
internal sealed class GuidAttribute : Attribute {
private Guid m_guid;
public Guid Guid {
get { return m_guid; }
}
GuidAttribute ()
{
m_guid = new Guid ();
}
public GuidAttribute (
uint a,
ushort b,
ushort c,
byte d,
byte e,
byte f,
byte g,
byte h,
byte i,
byte j,
byte k)
{
m_guid = new Guid ((int) a, (short) b, (short) c, d, e, f, g, h, i, j, k);
}
public static int GetValueFromGuid (Guid id, Type enumeration)
{
foreach (FieldInfo fi in enumeration.GetFields (BindingFlags.Static | BindingFlags.Public))
if (id == GetGuidAttribute (fi).Guid)
return (int) fi.GetValue (null);
return -1;
}
public static Guid GetGuidFromValue (int value, Type enumeration)
{
foreach (FieldInfo fi in enumeration.GetFields (BindingFlags.Static | BindingFlags.Public))
if (value == (int) fi.GetValue (null))
return GetGuidAttribute (fi).Guid;
return new Guid ();
}
static GuidAttribute GetGuidAttribute (FieldInfo fi)
{
GuidAttribute [] attributes = fi.GetCustomAttributes (typeof (GuidAttribute), false) as GuidAttribute [];
if (attributes == null || attributes.Length != 1)
return new GuidAttribute ();
return attributes [0];
}
}
}

View File

@@ -0,0 +1,34 @@
//
// ICodeVisitable.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal interface ICodeVisitable {
void Accept (ICodeVisitor visitor);
}
}

View File

@@ -0,0 +1,45 @@
//
// ICodeVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal interface ICodeVisitor {
void VisitMethodBody (MethodBody body);
void VisitInstructionCollection (InstructionCollection instructions);
void VisitInstruction (Instruction instr);
void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh);
void VisitExceptionHandler (ExceptionHandler eh);
void VisitVariableDefinitionCollection (VariableDefinitionCollection variables);
void VisitVariableDefinition (VariableDefinition var);
void VisitScopeCollection (ScopeCollection scopes);
void VisitScope (Scope scope);
void TerminateMethodBody (MethodBody body);
}
}

View File

@@ -0,0 +1,35 @@
//
// Document.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal interface IScopeProvider {
ScopeCollection Scopes { get; }
}
}

View File

@@ -0,0 +1,38 @@
//
// ISymbolReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
namespace Mono.Cecil.Cil {
internal interface ISymbolReader : IDisposable {
void Read (MethodBody body, IDictionary instructions);
}
}

View File

@@ -0,0 +1,36 @@
//
// ISymbolStoreFactory.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
internal interface ISymbolStoreFactory {
ISymbolReader CreateReader (ModuleDefinition module, string assemblyFileName);
ISymbolWriter CreateWriter (ModuleDefinition module, string assemblyFileName);
}
}

Some files were not shown because too many files have changed in this diff Show More