You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
21
external/linker/cecil/rocks/Mono.Cecil.Rocks.csproj
vendored
Normal file
21
external/linker/cecil/rocks/Mono.Cecil.Rocks.csproj
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}</ProjectGuid>
|
||||
<RootNamespace>Mono.Cecil.Rocks</RootNamespace>
|
||||
<AssemblyName>Mono.Cecil.Rocks</AssemblyName>
|
||||
<DefineConstants>$(DefineConstants);INSIDE_ROCKS</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ProjectInfo.cs" />
|
||||
<Compile Include="Mono.Cecil.Rocks\*.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Mono.Cecil.csproj">
|
||||
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
|
||||
<Name>Mono.Cecil</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="..\Mono.Cecil.props" />
|
||||
<Import Project="$(MSBuildCSharpTargets)" />
|
||||
</Project>
|
||||
16
external/linker/cecil/rocks/Mono.Cecil.Rocks/AssemblyInfo.cs
vendored
Normal file
16
external/linker/cecil/rocks/Mono.Cecil.Rocks/AssemblyInfo.cs
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyTitle ("Mono.Cecil.Rocks")]
|
||||
|
||||
[assembly: CLSCompliant (false)]
|
||||
264
external/linker/cecil/rocks/Mono.Cecil.Rocks/DocCommentId.cs
vendored
Normal file
264
external/linker/cecil/rocks/Mono.Cecil.Rocks/DocCommentId.cs
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
public class DocCommentId
|
||||
{
|
||||
StringBuilder id;
|
||||
|
||||
DocCommentId ()
|
||||
{
|
||||
id = new StringBuilder ();
|
||||
}
|
||||
|
||||
void WriteField (FieldDefinition field)
|
||||
{
|
||||
WriteDefinition ('F', field);
|
||||
}
|
||||
|
||||
void WriteEvent (EventDefinition @event)
|
||||
{
|
||||
WriteDefinition ('E', @event);
|
||||
}
|
||||
|
||||
void WriteType (TypeDefinition type)
|
||||
{
|
||||
id.Append ('T').Append (':');
|
||||
WriteTypeFullName (type);
|
||||
}
|
||||
|
||||
void WriteMethod (MethodDefinition method)
|
||||
{
|
||||
WriteDefinition ('M', method);
|
||||
|
||||
if (method.HasGenericParameters) {
|
||||
id.Append ('`').Append ('`');
|
||||
id.Append (method.GenericParameters.Count);
|
||||
}
|
||||
|
||||
if (method.HasParameters)
|
||||
WriteParameters (method.Parameters);
|
||||
|
||||
if (IsConversionOperator (method))
|
||||
WriteReturnType (method);
|
||||
}
|
||||
|
||||
static bool IsConversionOperator (MethodDefinition self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
return self.IsSpecialName
|
||||
&& (self.Name == "op_Explicit" || self.Name == "op_Implicit");
|
||||
}
|
||||
|
||||
void WriteReturnType (MethodDefinition method)
|
||||
{
|
||||
id.Append ('~');
|
||||
WriteTypeSignature (method.ReturnType);
|
||||
}
|
||||
|
||||
void WriteProperty (PropertyDefinition property)
|
||||
{
|
||||
WriteDefinition ('P', property);
|
||||
|
||||
if (property.HasParameters)
|
||||
WriteParameters (property.Parameters);
|
||||
}
|
||||
|
||||
void WriteParameters (IList<ParameterDefinition> parameters)
|
||||
{
|
||||
id.Append ('(');
|
||||
WriteList (parameters, p => WriteTypeSignature (p.ParameterType));
|
||||
id.Append (')');
|
||||
}
|
||||
|
||||
void WriteTypeSignature (TypeReference type)
|
||||
{
|
||||
switch (type.MetadataType)
|
||||
{
|
||||
case MetadataType.Array:
|
||||
WriteArrayTypeSignature ((ArrayType) type);
|
||||
break;
|
||||
case MetadataType.ByReference:
|
||||
WriteTypeSignature (((ByReferenceType) type).ElementType);
|
||||
id.Append ('@');
|
||||
break;
|
||||
case MetadataType.FunctionPointer:
|
||||
WriteFunctionPointerTypeSignature ((FunctionPointerType) type);
|
||||
break;
|
||||
case MetadataType.GenericInstance:
|
||||
WriteGenericInstanceTypeSignature ((GenericInstanceType) type);
|
||||
break;
|
||||
case MetadataType.Var:
|
||||
id.Append ('`');
|
||||
id.Append (((GenericParameter) type).Position);
|
||||
break;
|
||||
case MetadataType.MVar:
|
||||
id.Append ('`').Append ('`');
|
||||
id.Append (((GenericParameter) type).Position);
|
||||
break;
|
||||
case MetadataType.OptionalModifier:
|
||||
WriteModiferTypeSignature ((RequiredModifierType) type, '!');
|
||||
break;
|
||||
case MetadataType.RequiredModifier:
|
||||
WriteModiferTypeSignature ((RequiredModifierType) type, '|');
|
||||
break;
|
||||
case MetadataType.Pointer:
|
||||
WriteTypeSignature (((PointerType) type).ElementType);
|
||||
id.Append ('*');
|
||||
break;
|
||||
default:
|
||||
WriteTypeFullName (type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WriteGenericInstanceTypeSignature (GenericInstanceType type)
|
||||
{
|
||||
if (type.ElementType.IsTypeSpecification ())
|
||||
throw new NotSupportedException ();
|
||||
|
||||
WriteTypeFullName (type.ElementType, stripGenericArity: true);
|
||||
id.Append ('{');
|
||||
WriteList (type.GenericArguments, WriteTypeSignature);
|
||||
id.Append ('}');
|
||||
}
|
||||
|
||||
void WriteList<T> (IList<T> list, Action<T> action)
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++) {
|
||||
if (i > 0)
|
||||
id.Append (',');
|
||||
|
||||
action (list [i]);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteModiferTypeSignature (IModifierType type, char id)
|
||||
{
|
||||
WriteTypeSignature (type.ElementType);
|
||||
this.id.Append (id);
|
||||
WriteTypeSignature (type.ModifierType);
|
||||
}
|
||||
|
||||
void WriteFunctionPointerTypeSignature (FunctionPointerType type)
|
||||
{
|
||||
id.Append ("=FUNC:");
|
||||
WriteTypeSignature (type.ReturnType);
|
||||
|
||||
if (type.HasParameters)
|
||||
WriteParameters (type.Parameters);
|
||||
}
|
||||
|
||||
void WriteArrayTypeSignature (ArrayType type)
|
||||
{
|
||||
WriteTypeSignature (type.ElementType);
|
||||
|
||||
if (type.IsVector) {
|
||||
id.Append ("[]");
|
||||
return;
|
||||
}
|
||||
|
||||
id.Append ("[");
|
||||
|
||||
WriteList (type.Dimensions, dimension => {
|
||||
if (dimension.LowerBound.HasValue)
|
||||
id.Append (dimension.LowerBound.Value);
|
||||
|
||||
id.Append (':');
|
||||
|
||||
if (dimension.UpperBound.HasValue)
|
||||
id.Append (dimension.UpperBound.Value - (dimension.LowerBound.GetValueOrDefault () + 1));
|
||||
});
|
||||
|
||||
id.Append ("]");
|
||||
}
|
||||
|
||||
void WriteDefinition (char id, IMemberDefinition member)
|
||||
{
|
||||
this.id.Append (id)
|
||||
.Append (':');
|
||||
|
||||
WriteTypeFullName (member.DeclaringType);
|
||||
this.id.Append ('.');
|
||||
WriteItemName (member.Name);
|
||||
}
|
||||
|
||||
void WriteTypeFullName (TypeReference type, bool stripGenericArity = false)
|
||||
{
|
||||
if (type.DeclaringType != null) {
|
||||
WriteTypeFullName (type.DeclaringType);
|
||||
id.Append ('.');
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty (type.Namespace)) {
|
||||
id.Append (type.Namespace);
|
||||
id.Append ('.');
|
||||
}
|
||||
|
||||
var name = type.Name;
|
||||
|
||||
if (stripGenericArity) {
|
||||
var index = name.LastIndexOf ('`');
|
||||
if (index > 0)
|
||||
name = name.Substring (0, index);
|
||||
}
|
||||
|
||||
id.Append (name);
|
||||
}
|
||||
|
||||
void WriteItemName (string name)
|
||||
{
|
||||
id.Append (name.Replace ('.', '#'));
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return id.ToString ();
|
||||
}
|
||||
|
||||
public static string GetDocCommentId (IMemberDefinition member)
|
||||
{
|
||||
if (member == null)
|
||||
throw new ArgumentNullException ("member");
|
||||
|
||||
var documentId = new DocCommentId ();
|
||||
|
||||
switch (member.MetadataToken.TokenType)
|
||||
{
|
||||
case TokenType.Field:
|
||||
documentId.WriteField ((FieldDefinition) member);
|
||||
break;
|
||||
case TokenType.Method:
|
||||
documentId.WriteMethod ((MethodDefinition) member);
|
||||
break;
|
||||
case TokenType.TypeDef:
|
||||
documentId.WriteType ((TypeDefinition) member);
|
||||
break;
|
||||
case TokenType.Event:
|
||||
documentId.WriteEvent ((EventDefinition) member);
|
||||
break;
|
||||
case TokenType.Property:
|
||||
documentId.WriteProperty ((PropertyDefinition) member);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException (member.FullName);
|
||||
}
|
||||
|
||||
return documentId.ToString ();
|
||||
}
|
||||
}
|
||||
}
|
||||
41
external/linker/cecil/rocks/Mono.Cecil.Rocks/Functional.cs
vendored
Normal file
41
external/linker/cecil/rocks/Mono.Cecil.Rocks/Functional.cs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
static class Functional {
|
||||
|
||||
public static System.Func<A, R> Y<A, R> (System.Func<System.Func<A, R>, System.Func<A, R>> f)
|
||||
{
|
||||
System.Func<A, R> g = null;
|
||||
g = f (a => g (a));
|
||||
return g;
|
||||
}
|
||||
|
||||
public static IEnumerable<TSource> Prepend<TSource> (this IEnumerable<TSource> source, TSource element)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException ("source");
|
||||
|
||||
return PrependIterator (source, element);
|
||||
}
|
||||
|
||||
static IEnumerable<TSource> PrependIterator<TSource> (IEnumerable<TSource> source, TSource element)
|
||||
{
|
||||
yield return element;
|
||||
|
||||
foreach (var item in source)
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
217
external/linker/cecil/rocks/Mono.Cecil.Rocks/ILParser.cs
vendored
Normal file
217
external/linker/cecil/rocks/Mono.Cecil.Rocks/ILParser.cs
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Collections.Generic;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
#if INSIDE_ROCKS
|
||||
public
|
||||
#endif
|
||||
interface IILVisitor {
|
||||
void OnInlineNone (OpCode opcode);
|
||||
void OnInlineSByte (OpCode opcode, sbyte value);
|
||||
void OnInlineByte (OpCode opcode, byte value);
|
||||
void OnInlineInt32 (OpCode opcode, int value);
|
||||
void OnInlineInt64 (OpCode opcode, long value);
|
||||
void OnInlineSingle (OpCode opcode, float value);
|
||||
void OnInlineDouble (OpCode opcode, double value);
|
||||
void OnInlineString (OpCode opcode, string value);
|
||||
void OnInlineBranch (OpCode opcode, int offset);
|
||||
void OnInlineSwitch (OpCode opcode, int [] offsets);
|
||||
void OnInlineVariable (OpCode opcode, VariableDefinition variable);
|
||||
void OnInlineArgument (OpCode opcode, ParameterDefinition parameter);
|
||||
void OnInlineSignature (OpCode opcode, CallSite callSite);
|
||||
void OnInlineType (OpCode opcode, TypeReference type);
|
||||
void OnInlineField (OpCode opcode, FieldReference field);
|
||||
void OnInlineMethod (OpCode opcode, MethodReference method);
|
||||
}
|
||||
|
||||
#if INSIDE_ROCKS
|
||||
public
|
||||
#endif
|
||||
static class ILParser {
|
||||
|
||||
class ParseContext {
|
||||
public CodeReader Code { get; set; }
|
||||
public MetadataReader Metadata { get; set; }
|
||||
public Collection<VariableDefinition> Variables { get; set; }
|
||||
public IILVisitor Visitor { get; set; }
|
||||
}
|
||||
|
||||
public static void Parse (MethodDefinition method, IILVisitor visitor)
|
||||
{
|
||||
if (method == null)
|
||||
throw new ArgumentNullException ("method");
|
||||
if (visitor == null)
|
||||
throw new ArgumentNullException ("visitor");
|
||||
if (!method.HasBody || !method.HasImage)
|
||||
throw new ArgumentException ();
|
||||
|
||||
var context = CreateContext (method, visitor);
|
||||
var code = context.Code;
|
||||
|
||||
var flags = code.ReadByte ();
|
||||
|
||||
switch (flags & 0x3) {
|
||||
case 0x2: // tiny
|
||||
int code_size = flags >> 2;
|
||||
ParseCode (code_size, context);
|
||||
break;
|
||||
case 0x3: // fat
|
||||
code.Advance (-1);
|
||||
ParseFatMethod (context);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
static ParseContext CreateContext (MethodDefinition method, IILVisitor visitor)
|
||||
{
|
||||
var code = method.Module.Read (method, (_, reader) => reader.code);
|
||||
code.MoveTo (method);
|
||||
|
||||
return new ParseContext {
|
||||
Code = code,
|
||||
Metadata = code.reader,
|
||||
Visitor = visitor,
|
||||
};
|
||||
}
|
||||
|
||||
static void ParseFatMethod (ParseContext context)
|
||||
{
|
||||
var code = context.Code;
|
||||
|
||||
code.Advance (4);
|
||||
var code_size = code.ReadInt32 ();
|
||||
var local_var_token = code.ReadToken ();
|
||||
|
||||
if (local_var_token != MetadataToken.Zero)
|
||||
context.Variables = code.ReadVariables (local_var_token);
|
||||
|
||||
ParseCode (code_size, context);
|
||||
}
|
||||
|
||||
static void ParseCode (int code_size, ParseContext context)
|
||||
{
|
||||
var code = context.Code;
|
||||
var metadata = context.Metadata;
|
||||
var visitor = context.Visitor;
|
||||
|
||||
var start = code.Position;
|
||||
var end = start + code_size;
|
||||
|
||||
while (code.Position < end) {
|
||||
var il_opcode = code.ReadByte ();
|
||||
var opcode = il_opcode != 0xfe
|
||||
? OpCodes.OneByteOpCode [il_opcode]
|
||||
: OpCodes.TwoBytesOpCode [code.ReadByte ()];
|
||||
|
||||
switch (opcode.OperandType) {
|
||||
case OperandType.InlineNone:
|
||||
visitor.OnInlineNone (opcode);
|
||||
break;
|
||||
case OperandType.InlineSwitch:
|
||||
var length = code.ReadInt32 ();
|
||||
var branches = new int [length];
|
||||
for (int i = 0; i < length; i++)
|
||||
branches [i] = code.ReadInt32 ();
|
||||
visitor.OnInlineSwitch (opcode, branches);
|
||||
break;
|
||||
case OperandType.ShortInlineBrTarget:
|
||||
visitor.OnInlineBranch (opcode, code.ReadSByte ());
|
||||
break;
|
||||
case OperandType.InlineBrTarget:
|
||||
visitor.OnInlineBranch (opcode, code.ReadInt32 ());
|
||||
break;
|
||||
case OperandType.ShortInlineI:
|
||||
if (opcode == OpCodes.Ldc_I4_S)
|
||||
visitor.OnInlineSByte (opcode, code.ReadSByte ());
|
||||
else
|
||||
visitor.OnInlineByte (opcode, code.ReadByte ());
|
||||
break;
|
||||
case OperandType.InlineI:
|
||||
visitor.OnInlineInt32 (opcode, code.ReadInt32 ());
|
||||
break;
|
||||
case OperandType.InlineI8:
|
||||
visitor.OnInlineInt64 (opcode, code.ReadInt64 ());
|
||||
break;
|
||||
case OperandType.ShortInlineR:
|
||||
visitor.OnInlineSingle (opcode, code.ReadSingle ());
|
||||
break;
|
||||
case OperandType.InlineR:
|
||||
visitor.OnInlineDouble (opcode, code.ReadDouble ());
|
||||
break;
|
||||
case OperandType.InlineSig:
|
||||
visitor.OnInlineSignature (opcode, code.GetCallSite (code.ReadToken ()));
|
||||
break;
|
||||
case OperandType.InlineString:
|
||||
visitor.OnInlineString (opcode, code.GetString (code.ReadToken ()));
|
||||
break;
|
||||
case OperandType.ShortInlineArg:
|
||||
visitor.OnInlineArgument (opcode, code.GetParameter (code.ReadByte ()));
|
||||
break;
|
||||
case OperandType.InlineArg:
|
||||
visitor.OnInlineArgument (opcode, code.GetParameter (code.ReadInt16 ()));
|
||||
break;
|
||||
case OperandType.ShortInlineVar:
|
||||
visitor.OnInlineVariable (opcode, GetVariable (context, code.ReadByte ()));
|
||||
break;
|
||||
case OperandType.InlineVar:
|
||||
visitor.OnInlineVariable (opcode, GetVariable (context, code.ReadInt16 ()));
|
||||
break;
|
||||
case OperandType.InlineTok:
|
||||
case OperandType.InlineField:
|
||||
case OperandType.InlineMethod:
|
||||
case OperandType.InlineType:
|
||||
var member = metadata.LookupToken (code.ReadToken ());
|
||||
switch (member.MetadataToken.TokenType) {
|
||||
case TokenType.TypeDef:
|
||||
case TokenType.TypeRef:
|
||||
case TokenType.TypeSpec:
|
||||
visitor.OnInlineType (opcode, (TypeReference) member);
|
||||
break;
|
||||
case TokenType.Method:
|
||||
case TokenType.MethodSpec:
|
||||
visitor.OnInlineMethod (opcode, (MethodReference) member);
|
||||
break;
|
||||
case TokenType.Field:
|
||||
visitor.OnInlineField (opcode, (FieldReference) member);
|
||||
break;
|
||||
case TokenType.MemberRef:
|
||||
var field_ref = member as FieldReference;
|
||||
if (field_ref != null) {
|
||||
visitor.OnInlineField (opcode, field_ref);
|
||||
break;
|
||||
}
|
||||
|
||||
var method_ref = member as MethodReference;
|
||||
if (method_ref != null) {
|
||||
visitor.OnInlineMethod (opcode, method_ref);
|
||||
break;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static VariableDefinition GetVariable (ParseContext context, int index)
|
||||
{
|
||||
return context.Variables [index];
|
||||
}
|
||||
}
|
||||
}
|
||||
389
external/linker/cecil/rocks/Mono.Cecil.Rocks/MethodBodyRocks.cs
vendored
Normal file
389
external/linker/cecil/rocks/Mono.Cecil.Rocks/MethodBodyRocks.cs
vendored
Normal file
@@ -0,0 +1,389 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
#if INSIDE_ROCKS
|
||||
public
|
||||
#endif
|
||||
static class MethodBodyRocks {
|
||||
|
||||
public static void SimplifyMacros (this MethodBody self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
foreach (var instruction in self.Instructions) {
|
||||
if (instruction.OpCode.OpCodeType != OpCodeType.Macro)
|
||||
continue;
|
||||
|
||||
switch (instruction.OpCode.Code) {
|
||||
case Code.Ldarg_0:
|
||||
ExpandMacro (instruction, OpCodes.Ldarg, self.GetParameter (0));
|
||||
break;
|
||||
case Code.Ldarg_1:
|
||||
ExpandMacro (instruction, OpCodes.Ldarg, self.GetParameter (1));
|
||||
break;
|
||||
case Code.Ldarg_2:
|
||||
ExpandMacro (instruction, OpCodes.Ldarg, self.GetParameter (2));
|
||||
break;
|
||||
case Code.Ldarg_3:
|
||||
ExpandMacro (instruction, OpCodes.Ldarg, self.GetParameter (3));
|
||||
break;
|
||||
case Code.Ldloc_0:
|
||||
ExpandMacro (instruction, OpCodes.Ldloc, self.Variables [0]);
|
||||
break;
|
||||
case Code.Ldloc_1:
|
||||
ExpandMacro (instruction, OpCodes.Ldloc, self.Variables [1]);
|
||||
break;
|
||||
case Code.Ldloc_2:
|
||||
ExpandMacro (instruction, OpCodes.Ldloc, self.Variables [2]);
|
||||
break;
|
||||
case Code.Ldloc_3:
|
||||
ExpandMacro (instruction, OpCodes.Ldloc, self.Variables [3]);
|
||||
break;
|
||||
case Code.Stloc_0:
|
||||
ExpandMacro (instruction, OpCodes.Stloc, self.Variables [0]);
|
||||
break;
|
||||
case Code.Stloc_1:
|
||||
ExpandMacro (instruction, OpCodes.Stloc, self.Variables [1]);
|
||||
break;
|
||||
case Code.Stloc_2:
|
||||
ExpandMacro (instruction, OpCodes.Stloc, self.Variables [2]);
|
||||
break;
|
||||
case Code.Stloc_3:
|
||||
ExpandMacro (instruction, OpCodes.Stloc, self.Variables [3]);
|
||||
break;
|
||||
case Code.Ldarg_S:
|
||||
instruction.OpCode = OpCodes.Ldarg;
|
||||
break;
|
||||
case Code.Ldarga_S:
|
||||
instruction.OpCode = OpCodes.Ldarga;
|
||||
break;
|
||||
case Code.Starg_S:
|
||||
instruction.OpCode = OpCodes.Starg;
|
||||
break;
|
||||
case Code.Ldloc_S:
|
||||
instruction.OpCode = OpCodes.Ldloc;
|
||||
break;
|
||||
case Code.Ldloca_S:
|
||||
instruction.OpCode = OpCodes.Ldloca;
|
||||
break;
|
||||
case Code.Stloc_S:
|
||||
instruction.OpCode = OpCodes.Stloc;
|
||||
break;
|
||||
case Code.Ldc_I4_M1:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, -1);
|
||||
break;
|
||||
case Code.Ldc_I4_0:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 0);
|
||||
break;
|
||||
case Code.Ldc_I4_1:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 1);
|
||||
break;
|
||||
case Code.Ldc_I4_2:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 2);
|
||||
break;
|
||||
case Code.Ldc_I4_3:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 3);
|
||||
break;
|
||||
case Code.Ldc_I4_4:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 4);
|
||||
break;
|
||||
case Code.Ldc_I4_5:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 5);
|
||||
break;
|
||||
case Code.Ldc_I4_6:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 6);
|
||||
break;
|
||||
case Code.Ldc_I4_7:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 7);
|
||||
break;
|
||||
case Code.Ldc_I4_8:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, 8);
|
||||
break;
|
||||
case Code.Ldc_I4_S:
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, (int) (sbyte) instruction.Operand);
|
||||
break;
|
||||
case Code.Br_S:
|
||||
instruction.OpCode = OpCodes.Br;
|
||||
break;
|
||||
case Code.Brfalse_S:
|
||||
instruction.OpCode = OpCodes.Brfalse;
|
||||
break;
|
||||
case Code.Brtrue_S:
|
||||
instruction.OpCode = OpCodes.Brtrue;
|
||||
break;
|
||||
case Code.Beq_S:
|
||||
instruction.OpCode = OpCodes.Beq;
|
||||
break;
|
||||
case Code.Bge_S:
|
||||
instruction.OpCode = OpCodes.Bge;
|
||||
break;
|
||||
case Code.Bgt_S:
|
||||
instruction.OpCode = OpCodes.Bgt;
|
||||
break;
|
||||
case Code.Ble_S:
|
||||
instruction.OpCode = OpCodes.Ble;
|
||||
break;
|
||||
case Code.Blt_S:
|
||||
instruction.OpCode = OpCodes.Blt;
|
||||
break;
|
||||
case Code.Bne_Un_S:
|
||||
instruction.OpCode = OpCodes.Bne_Un;
|
||||
break;
|
||||
case Code.Bge_Un_S:
|
||||
instruction.OpCode = OpCodes.Bge_Un;
|
||||
break;
|
||||
case Code.Bgt_Un_S:
|
||||
instruction.OpCode = OpCodes.Bgt_Un;
|
||||
break;
|
||||
case Code.Ble_Un_S:
|
||||
instruction.OpCode = OpCodes.Ble_Un;
|
||||
break;
|
||||
case Code.Blt_Un_S:
|
||||
instruction.OpCode = OpCodes.Blt_Un;
|
||||
break;
|
||||
case Code.Leave_S:
|
||||
instruction.OpCode = OpCodes.Leave;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ExpandMacro (Instruction instruction, OpCode opcode, object operand)
|
||||
{
|
||||
instruction.OpCode = opcode;
|
||||
instruction.Operand = operand;
|
||||
}
|
||||
|
||||
static void MakeMacro (Instruction instruction, OpCode opcode)
|
||||
{
|
||||
instruction.OpCode = opcode;
|
||||
instruction.Operand = null;
|
||||
}
|
||||
|
||||
public static void OptimizeMacros (this MethodBody self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
var method = self.Method;
|
||||
|
||||
foreach (var instruction in self.Instructions) {
|
||||
int index;
|
||||
switch (instruction.OpCode.Code) {
|
||||
case Code.Ldarg:
|
||||
index = ((ParameterDefinition) instruction.Operand).Index;
|
||||
if (index == -1 && instruction.Operand == self.ThisParameter)
|
||||
index = 0;
|
||||
else if (method.HasThis)
|
||||
index++;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
MakeMacro (instruction, OpCodes.Ldarg_0);
|
||||
break;
|
||||
case 1:
|
||||
MakeMacro (instruction, OpCodes.Ldarg_1);
|
||||
break;
|
||||
case 2:
|
||||
MakeMacro (instruction, OpCodes.Ldarg_2);
|
||||
break;
|
||||
case 3:
|
||||
MakeMacro (instruction, OpCodes.Ldarg_3);
|
||||
break;
|
||||
default:
|
||||
if (index < 256)
|
||||
ExpandMacro (instruction, OpCodes.Ldarg_S, instruction.Operand);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Code.Ldloc:
|
||||
index = ((VariableDefinition) instruction.Operand).Index;
|
||||
switch (index) {
|
||||
case 0:
|
||||
MakeMacro (instruction, OpCodes.Ldloc_0);
|
||||
break;
|
||||
case 1:
|
||||
MakeMacro (instruction, OpCodes.Ldloc_1);
|
||||
break;
|
||||
case 2:
|
||||
MakeMacro (instruction, OpCodes.Ldloc_2);
|
||||
break;
|
||||
case 3:
|
||||
MakeMacro (instruction, OpCodes.Ldloc_3);
|
||||
break;
|
||||
default:
|
||||
if (index < 256)
|
||||
ExpandMacro (instruction, OpCodes.Ldloc_S, instruction.Operand);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Code.Stloc:
|
||||
index = ((VariableDefinition) instruction.Operand).Index;
|
||||
switch (index) {
|
||||
case 0:
|
||||
MakeMacro (instruction, OpCodes.Stloc_0);
|
||||
break;
|
||||
case 1:
|
||||
MakeMacro (instruction, OpCodes.Stloc_1);
|
||||
break;
|
||||
case 2:
|
||||
MakeMacro (instruction, OpCodes.Stloc_2);
|
||||
break;
|
||||
case 3:
|
||||
MakeMacro (instruction, OpCodes.Stloc_3);
|
||||
break;
|
||||
default:
|
||||
if (index < 256)
|
||||
ExpandMacro (instruction, OpCodes.Stloc_S, instruction.Operand);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Code.Ldarga:
|
||||
index = ((ParameterDefinition) instruction.Operand).Index;
|
||||
if (index == -1 && instruction.Operand == self.ThisParameter)
|
||||
index = 0;
|
||||
else if (method.HasThis)
|
||||
index++;
|
||||
if (index < 256)
|
||||
ExpandMacro (instruction, OpCodes.Ldarga_S, instruction.Operand);
|
||||
break;
|
||||
case Code.Ldloca:
|
||||
if (((VariableDefinition) instruction.Operand).Index < 256)
|
||||
ExpandMacro (instruction, OpCodes.Ldloca_S, instruction.Operand);
|
||||
break;
|
||||
case Code.Ldc_I4:
|
||||
int i = (int) instruction.Operand;
|
||||
switch (i) {
|
||||
case -1:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_M1);
|
||||
break;
|
||||
case 0:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_0);
|
||||
break;
|
||||
case 1:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_1);
|
||||
break;
|
||||
case 2:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_2);
|
||||
break;
|
||||
case 3:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_3);
|
||||
break;
|
||||
case 4:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_4);
|
||||
break;
|
||||
case 5:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_5);
|
||||
break;
|
||||
case 6:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_6);
|
||||
break;
|
||||
case 7:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_7);
|
||||
break;
|
||||
case 8:
|
||||
MakeMacro (instruction, OpCodes.Ldc_I4_8);
|
||||
break;
|
||||
default:
|
||||
if (i >= -128 && i < 128)
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4_S, (sbyte) i);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OptimizeBranches (self);
|
||||
}
|
||||
|
||||
static void OptimizeBranches (MethodBody body)
|
||||
{
|
||||
ComputeOffsets (body);
|
||||
|
||||
foreach (var instruction in body.Instructions) {
|
||||
if (instruction.OpCode.OperandType != OperandType.InlineBrTarget)
|
||||
continue;
|
||||
|
||||
if (OptimizeBranch (instruction))
|
||||
ComputeOffsets (body);
|
||||
}
|
||||
}
|
||||
|
||||
static bool OptimizeBranch (Instruction instruction)
|
||||
{
|
||||
var offset = ((Instruction) instruction.Operand).Offset - (instruction.Offset + instruction.OpCode.Size + 4);
|
||||
if (!(offset >= -128 && offset <= 127))
|
||||
return false;
|
||||
|
||||
switch (instruction.OpCode.Code) {
|
||||
case Code.Br:
|
||||
instruction.OpCode = OpCodes.Br_S;
|
||||
break;
|
||||
case Code.Brfalse:
|
||||
instruction.OpCode = OpCodes.Brfalse_S;
|
||||
break;
|
||||
case Code.Brtrue:
|
||||
instruction.OpCode = OpCodes.Brtrue_S;
|
||||
break;
|
||||
case Code.Beq:
|
||||
instruction.OpCode = OpCodes.Beq_S;
|
||||
break;
|
||||
case Code.Bge:
|
||||
instruction.OpCode = OpCodes.Bge_S;
|
||||
break;
|
||||
case Code.Bgt:
|
||||
instruction.OpCode = OpCodes.Bgt_S;
|
||||
break;
|
||||
case Code.Ble:
|
||||
instruction.OpCode = OpCodes.Ble_S;
|
||||
break;
|
||||
case Code.Blt:
|
||||
instruction.OpCode = OpCodes.Blt_S;
|
||||
break;
|
||||
case Code.Bne_Un:
|
||||
instruction.OpCode = OpCodes.Bne_Un_S;
|
||||
break;
|
||||
case Code.Bge_Un:
|
||||
instruction.OpCode = OpCodes.Bge_Un_S;
|
||||
break;
|
||||
case Code.Bgt_Un:
|
||||
instruction.OpCode = OpCodes.Bgt_Un_S;
|
||||
break;
|
||||
case Code.Ble_Un:
|
||||
instruction.OpCode = OpCodes.Ble_Un_S;
|
||||
break;
|
||||
case Code.Blt_Un:
|
||||
instruction.OpCode = OpCodes.Blt_Un_S;
|
||||
break;
|
||||
case Code.Leave:
|
||||
instruction.OpCode = OpCodes.Leave_S;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ComputeOffsets (MethodBody body)
|
||||
{
|
||||
var offset = 0;
|
||||
foreach (var instruction in body.Instructions) {
|
||||
instruction.Offset = offset;
|
||||
offset += instruction.GetSize ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
72
external/linker/cecil/rocks/Mono.Cecil.Rocks/MethodDefinitionRocks.cs
vendored
Normal file
72
external/linker/cecil/rocks/Mono.Cecil.Rocks/MethodDefinitionRocks.cs
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
#if INSIDE_ROCKS
|
||||
public
|
||||
#endif
|
||||
static class MethodDefinitionRocks {
|
||||
|
||||
public static MethodDefinition GetBaseMethod (this MethodDefinition self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
if (!self.IsVirtual)
|
||||
return self;
|
||||
if (self.IsNewSlot)
|
||||
return self;
|
||||
|
||||
var base_type = ResolveBaseType (self.DeclaringType);
|
||||
while (base_type != null) {
|
||||
var @base = GetMatchingMethod (base_type, self);
|
||||
if (@base != null)
|
||||
return @base;
|
||||
|
||||
base_type = ResolveBaseType (base_type);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
public static MethodDefinition GetOriginalBaseMethod (this MethodDefinition self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
while (true) {
|
||||
var @base = self.GetBaseMethod ();
|
||||
if (@base == self)
|
||||
return self;
|
||||
|
||||
self = @base;
|
||||
}
|
||||
}
|
||||
|
||||
static TypeDefinition ResolveBaseType (TypeDefinition type)
|
||||
{
|
||||
if (type == null)
|
||||
return null;
|
||||
|
||||
var base_type = type.BaseType;
|
||||
if (base_type == null)
|
||||
return null;
|
||||
|
||||
return base_type.Resolve ();
|
||||
}
|
||||
|
||||
static MethodDefinition GetMatchingMethod (TypeDefinition type, MethodDefinition method)
|
||||
{
|
||||
return MetadataResolver.GetMethod (type.Methods, method);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
external/linker/cecil/rocks/Mono.Cecil.Rocks/ModuleDefinitionRocks.cs
vendored
Normal file
32
external/linker/cecil/rocks/Mono.Cecil.Rocks/ModuleDefinitionRocks.cs
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
#if INSIDE_ROCKS
|
||||
public
|
||||
#endif
|
||||
static class ModuleDefinitionRocks {
|
||||
|
||||
public static IEnumerable<TypeDefinition> GetAllTypes (this ModuleDefinition self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
// it was fun to write, but we need a somewhat less convoluted implementation
|
||||
return self.Types.SelectMany (
|
||||
Functional.Y<TypeDefinition, IEnumerable<TypeDefinition>> (f => type => type.NestedTypes.SelectMany (f).Prepend (type)));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
external/linker/cecil/rocks/Mono.Cecil.Rocks/ParameterReferenceRocks.cs
vendored
Normal file
11
external/linker/cecil/rocks/Mono.Cecil.Rocks/ParameterReferenceRocks.cs
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
public static class ParameterReferenceRocks {
|
||||
|
||||
public static int GetSequence (this ParameterReference self)
|
||||
{
|
||||
return self.Index + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
152
external/linker/cecil/rocks/Mono.Cecil.Rocks/SecurityDeclarationRocks.cs
vendored
Normal file
152
external/linker/cecil/rocks/Mono.Cecil.Rocks/SecurityDeclarationRocks.cs
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Security;
|
||||
using SSP = System.Security.Permissions;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
#if INSIDE_ROCKS
|
||||
public
|
||||
#endif
|
||||
static class SecurityDeclarationRocks {
|
||||
|
||||
public static PermissionSet ToPermissionSet (this SecurityDeclaration self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
PermissionSet set;
|
||||
if (TryProcessPermissionSetAttribute (self, out set))
|
||||
return set;
|
||||
|
||||
return CreatePermissionSet (self);
|
||||
}
|
||||
|
||||
static bool TryProcessPermissionSetAttribute (SecurityDeclaration declaration, out PermissionSet set)
|
||||
{
|
||||
set = null;
|
||||
|
||||
if (!declaration.HasSecurityAttributes && declaration.SecurityAttributes.Count != 1)
|
||||
return false;
|
||||
|
||||
var security_attribute = declaration.SecurityAttributes [0];
|
||||
if (!security_attribute.AttributeType.IsTypeOf ("System.Security.Permissions", "PermissionSetAttribute"))
|
||||
return false;
|
||||
|
||||
var attribute = new SSP.PermissionSetAttribute ((SSP.SecurityAction) declaration.Action);
|
||||
|
||||
var named_argument = security_attribute.Properties [0];
|
||||
string value = (string) named_argument.Argument.Value;
|
||||
switch (named_argument.Name) {
|
||||
case "XML":
|
||||
attribute.XML = value;
|
||||
break;
|
||||
case "Name":
|
||||
attribute.Name = value;
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException (named_argument.Name);
|
||||
}
|
||||
|
||||
set = attribute.CreatePermissionSet ();
|
||||
return true;
|
||||
}
|
||||
|
||||
static PermissionSet CreatePermissionSet (SecurityDeclaration declaration)
|
||||
{
|
||||
var set = new PermissionSet (SSP.PermissionState.None);
|
||||
|
||||
foreach (var attribute in declaration.SecurityAttributes) {
|
||||
var permission = CreatePermission (declaration, attribute);
|
||||
set.AddPermission (permission);
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
static IPermission CreatePermission (SecurityDeclaration declaration, SecurityAttribute attribute)
|
||||
{
|
||||
var attribute_type = Type.GetType (attribute.AttributeType.FullName);
|
||||
if (attribute_type == null)
|
||||
throw new ArgumentException ("attribute");
|
||||
|
||||
var security_attribute = CreateSecurityAttribute (attribute_type, declaration);
|
||||
if (security_attribute == null)
|
||||
throw new InvalidOperationException ();
|
||||
|
||||
CompleteSecurityAttribute (security_attribute, attribute);
|
||||
|
||||
return security_attribute.CreatePermission ();
|
||||
}
|
||||
|
||||
static void CompleteSecurityAttribute (SSP.SecurityAttribute security_attribute, SecurityAttribute attribute)
|
||||
{
|
||||
if (attribute.HasFields)
|
||||
CompleteSecurityAttributeFields (security_attribute, attribute);
|
||||
|
||||
if (attribute.HasProperties)
|
||||
CompleteSecurityAttributeProperties (security_attribute, attribute);
|
||||
}
|
||||
|
||||
static void CompleteSecurityAttributeFields (SSP.SecurityAttribute security_attribute, SecurityAttribute attribute)
|
||||
{
|
||||
var type = security_attribute.GetType ();
|
||||
|
||||
foreach (var named_argument in attribute.Fields)
|
||||
type.GetField (named_argument.Name).SetValue (security_attribute, named_argument.Argument.Value);
|
||||
}
|
||||
|
||||
static void CompleteSecurityAttributeProperties (SSP.SecurityAttribute security_attribute, SecurityAttribute attribute)
|
||||
{
|
||||
var type = security_attribute.GetType ();
|
||||
|
||||
foreach (var named_argument in attribute.Properties)
|
||||
type.GetProperty (named_argument.Name).SetValue (security_attribute, named_argument.Argument.Value, null);
|
||||
}
|
||||
|
||||
static SSP.SecurityAttribute CreateSecurityAttribute (Type attribute_type, SecurityDeclaration declaration)
|
||||
{
|
||||
SSP.SecurityAttribute security_attribute;
|
||||
try {
|
||||
security_attribute = (SSP.SecurityAttribute) Activator.CreateInstance (
|
||||
attribute_type, new object [] { (SSP.SecurityAction) declaration.Action });
|
||||
} catch (MissingMethodException) {
|
||||
security_attribute = (SSP.SecurityAttribute) Activator.CreateInstance (attribute_type, new object [0]);
|
||||
}
|
||||
|
||||
return security_attribute;
|
||||
}
|
||||
|
||||
public static SecurityDeclaration ToSecurityDeclaration (this PermissionSet self, SecurityAction action, ModuleDefinition module)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
if (module == null)
|
||||
throw new ArgumentNullException ("module");
|
||||
|
||||
var declaration = new SecurityDeclaration (action);
|
||||
|
||||
var attribute = new SecurityAttribute (
|
||||
module.TypeSystem.LookupType ("System.Security.Permissions", "PermissionSetAttribute"));
|
||||
|
||||
attribute.Properties.Add (
|
||||
new CustomAttributeNamedArgument (
|
||||
"XML",
|
||||
new CustomAttributeArgument (
|
||||
module.TypeSystem.String, self.ToXml ().ToString ())));
|
||||
|
||||
declaration.SecurityAttributes.Add (attribute);
|
||||
|
||||
return declaration;
|
||||
}
|
||||
}
|
||||
}
|
||||
65
external/linker/cecil/rocks/Mono.Cecil.Rocks/TypeDefinitionRocks.cs
vendored
Normal file
65
external/linker/cecil/rocks/Mono.Cecil.Rocks/TypeDefinitionRocks.cs
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
#if INSIDE_ROCKS
|
||||
public
|
||||
#endif
|
||||
static class TypeDefinitionRocks {
|
||||
|
||||
public static IEnumerable<MethodDefinition> GetConstructors (this TypeDefinition self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
if (!self.HasMethods)
|
||||
return Empty<MethodDefinition>.Array;
|
||||
|
||||
return self.Methods.Where (method => method.IsConstructor);
|
||||
}
|
||||
|
||||
public static MethodDefinition GetStaticConstructor (this TypeDefinition self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
if (!self.HasMethods)
|
||||
return null;
|
||||
|
||||
return self.GetConstructors ().FirstOrDefault (ctor => ctor.IsStatic);
|
||||
}
|
||||
|
||||
public static IEnumerable<MethodDefinition> GetMethods (this TypeDefinition self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
|
||||
if (!self.HasMethods)
|
||||
return Empty<MethodDefinition>.Array;
|
||||
|
||||
return self.Methods.Where (method => !method.IsConstructor);
|
||||
}
|
||||
|
||||
public static TypeReference GetEnumUnderlyingType (this TypeDefinition self)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
if (!self.IsEnum)
|
||||
throw new ArgumentException ();
|
||||
|
||||
return Mixin.GetEnumUnderlyingType (self);
|
||||
}
|
||||
}
|
||||
}
|
||||
89
external/linker/cecil/rocks/Mono.Cecil.Rocks/TypeReferenceRocks.cs
vendored
Normal file
89
external/linker/cecil/rocks/Mono.Cecil.Rocks/TypeReferenceRocks.cs
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mono.Cecil.Rocks {
|
||||
|
||||
#if INSIDE_ROCKS
|
||||
public
|
||||
#endif
|
||||
static class TypeReferenceRocks {
|
||||
|
||||
public static ArrayType MakeArrayType (this TypeReference self)
|
||||
{
|
||||
return new ArrayType (self);
|
||||
}
|
||||
|
||||
public static ArrayType MakeArrayType (this TypeReference self, int rank)
|
||||
{
|
||||
if (rank == 0)
|
||||
throw new ArgumentOutOfRangeException ("rank");
|
||||
|
||||
var array = new ArrayType (self);
|
||||
|
||||
for (int i = 1; i < rank; i++)
|
||||
array.Dimensions.Add (new ArrayDimension ());
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public static PointerType MakePointerType (this TypeReference self)
|
||||
{
|
||||
return new PointerType (self);
|
||||
}
|
||||
|
||||
public static ByReferenceType MakeByReferenceType (this TypeReference self)
|
||||
{
|
||||
return new ByReferenceType (self);
|
||||
}
|
||||
|
||||
public static OptionalModifierType MakeOptionalModifierType (this TypeReference self, TypeReference modifierType)
|
||||
{
|
||||
return new OptionalModifierType (modifierType, self);
|
||||
}
|
||||
|
||||
public static RequiredModifierType MakeRequiredModifierType (this TypeReference self, TypeReference modifierType)
|
||||
{
|
||||
return new RequiredModifierType (modifierType, self);
|
||||
}
|
||||
|
||||
public static GenericInstanceType MakeGenericInstanceType (this TypeReference self, params TypeReference [] arguments)
|
||||
{
|
||||
if (self == null)
|
||||
throw new ArgumentNullException ("self");
|
||||
if (arguments == null)
|
||||
throw new ArgumentNullException ("arguments");
|
||||
if (arguments.Length == 0)
|
||||
throw new ArgumentException ();
|
||||
if (self.GenericParameters.Count != arguments.Length)
|
||||
throw new ArgumentException ();
|
||||
|
||||
var instance = new GenericInstanceType (self);
|
||||
|
||||
foreach (var argument in arguments)
|
||||
instance.GenericArguments.Add (argument);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static PinnedType MakePinnedType (this TypeReference self)
|
||||
{
|
||||
return new PinnedType (self);
|
||||
}
|
||||
|
||||
public static SentinelType MakeSentinelType (this TypeReference self)
|
||||
{
|
||||
return new SentinelType (self);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
external/linker/cecil/rocks/Test/Mono.Cecil.Rocks.Tests.csproj
vendored
Normal file
30
external/linker/cecil/rocks/Test/Mono.Cecil.Rocks.Tests.csproj
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}</ProjectGuid>
|
||||
<RootNamespace>Mono.Cecil.Rocks.Tests</RootNamespace>
|
||||
<AssemblyName>Mono.Cecil.Rocks.Tests</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Mono.Cecil.csproj">
|
||||
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
|
||||
<Name>Mono.Cecil</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Test\Mono.Cecil.Tests.csproj">
|
||||
<Project>{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}</Project>
|
||||
<Name>Mono.Cecil.Tests</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Mono.Cecil.Rocks.csproj">
|
||||
<Project>{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}</Project>
|
||||
<Name>Mono.Cecil.Rocks</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Mono.Cecil.Tests\*.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\**\*" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\Mono.Cecil.Tests.props" />
|
||||
<Import Project="$(MSBuildCSharpTargets)" />
|
||||
</Project>
|
||||
264
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/DocCommentIdTests.cs
vendored
Normal file
264
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/DocCommentIdTests.cs
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
namespace N
|
||||
{
|
||||
/// <summary>
|
||||
/// ID string generated is "T:N.X".
|
||||
/// </summary>
|
||||
public class X
|
||||
{
|
||||
/// <summary>
|
||||
/// ID string generated is "M:N.X.#ctor".
|
||||
/// </summary>
|
||||
public X() { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "M:N.X.#ctor(System.Int32)".
|
||||
/// </summary>
|
||||
/// <param name="i">Describe parameter.</param>
|
||||
public X(int i) { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "F:N.X.q".
|
||||
/// </summary>
|
||||
public string q;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "F:N.X.PI".
|
||||
/// </summary>
|
||||
public const double PI = 3.14;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "M:N.X.f".
|
||||
/// </summary>
|
||||
public int f() { return 1; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "M:N.X.bb(System.String,System.Int32@)".
|
||||
/// </summary>
|
||||
public int bb(string s, ref int y) { return 1; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "M:N.X.gg(System.Int16[],System.Int32[0:,0:])".
|
||||
/// </summary>
|
||||
public int gg(short[] array1, int[,] array) { return 0; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "M:N.X.op_Addition(N.X,N.X)".
|
||||
/// </summary>
|
||||
public static X operator +(X x, X xx) { return x; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "P:N.X.prop".
|
||||
/// </summary>
|
||||
public int prop { get { return 1; } set { } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "E:N.X.d".
|
||||
/// </summary>
|
||||
#pragma warning disable 67
|
||||
public event D d;
|
||||
#pragma warning restore 67
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "P:N.X.Item(System.String)".
|
||||
/// </summary>
|
||||
public int this[string s] { get { return 1; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "T:N.X.Nested".
|
||||
/// </summary>
|
||||
public class Nested { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "T:N.X.D".
|
||||
/// </summary>
|
||||
public delegate void D(int i);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID string generated is "M:N.X.op_Explicit(N.X)~System.Int32".
|
||||
/// </summary>
|
||||
public static explicit operator int(X x) { return 1; }
|
||||
|
||||
public static void Linq (IEnumerable<string> enumerable, Func<string> selector)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Mono.Cecil.Tests {
|
||||
|
||||
[TestFixture]
|
||||
public class DocCommentIdTests {
|
||||
|
||||
[Test]
|
||||
public void TypeDef ()
|
||||
{
|
||||
AssertDocumentID ("T:N.X", GetTestType ());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParameterlessCtor ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var ctor = type.GetConstructors ().Single (m => m.Parameters.Count == 0);
|
||||
|
||||
AssertDocumentID ("M:N.X.#ctor", ctor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CtorWithParameters ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var ctor = type.GetConstructors ().Single (m => m.Parameters.Count == 1);
|
||||
|
||||
AssertDocumentID ("M:N.X.#ctor(System.Int32)", ctor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Field ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var field = type.Fields.Single (m => m.Name == "q");
|
||||
|
||||
AssertDocumentID ("F:N.X.q", field);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConstField ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var field = type.Fields.Single (m => m.Name == "PI");
|
||||
|
||||
AssertDocumentID ("F:N.X.PI", field);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParameterlessMethod ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var method = type.Methods.Single (m => m.Name == "f");
|
||||
|
||||
AssertDocumentID ("M:N.X.f", method);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodWithByRefParameters ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var method = type.Methods.Single (m => m.Name == "bb");
|
||||
|
||||
AssertDocumentID ("M:N.X.bb(System.String,System.Int32@)", method);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodWithArrayParameters ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var method = type.Methods.Single (m => m.Name == "gg");
|
||||
|
||||
AssertDocumentID ("M:N.X.gg(System.Int16[],System.Int32[0:,0:])", method);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OpAddition ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var op = type.Methods.Single (m => m.Name == "op_Addition");
|
||||
|
||||
AssertDocumentID ("M:N.X.op_Addition(N.X,N.X)", op);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OpExplicit ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var op = type.Methods.Single (m => m.Name == "op_Explicit");
|
||||
|
||||
AssertDocumentID ("M:N.X.op_Explicit(N.X)~System.Int32", op);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Property ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var property = type.Properties.Single (p => p.Name == "prop");
|
||||
|
||||
AssertDocumentID ("P:N.X.prop", property);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Indexer ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var indexer = type.Properties.Single (p => p.Name == "Item");
|
||||
|
||||
AssertDocumentID ("P:N.X.Item(System.String)", indexer);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Event ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var @event = type.Events.Single (e => e.Name == "d");
|
||||
|
||||
AssertDocumentID ("E:N.X.d", @event);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Delegate ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var @delegate = type.NestedTypes.Single (t => t.Name == "D");
|
||||
|
||||
AssertDocumentID ("T:N.X.D", @delegate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NestedType ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var nestedType = type.NestedTypes.Single (t => t.Name == "Nested");
|
||||
|
||||
AssertDocumentID ("T:N.X.Nested", nestedType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Linq ()
|
||||
{
|
||||
var type = GetTestType ();
|
||||
var method = type.GetMethod ("Linq");
|
||||
|
||||
AssertDocumentID ("M:N.X.Linq(System.Collections.Generic.IEnumerable{System.String},System.Func{System.String})", method);
|
||||
}
|
||||
|
||||
TypeDefinition GetTestType ()
|
||||
{
|
||||
return typeof (N.X).ToDefinition ();
|
||||
}
|
||||
|
||||
static void AssertDocumentID (string docId, IMemberDefinition member)
|
||||
{
|
||||
Assert.AreEqual (docId, DocCommentId.GetDocCommentId (member));
|
||||
}
|
||||
}
|
||||
}
|
||||
66
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/MethodDefinitionRocksTests.cs
vendored
Normal file
66
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/MethodDefinitionRocksTests.cs
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Linq;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
namespace Mono.Cecil.Tests {
|
||||
|
||||
[TestFixture]
|
||||
public class MethodDefinitionRocksTests : BaseTestFixture {
|
||||
|
||||
abstract class Foo {
|
||||
public abstract void DoFoo ();
|
||||
public abstract void DoBar ();
|
||||
}
|
||||
|
||||
class Bar : Foo {
|
||||
public override void DoFoo ()
|
||||
{
|
||||
}
|
||||
|
||||
public override void DoBar ()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class Baz : Bar {
|
||||
public override void DoFoo ()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual new void DoBar ()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBaseMethod ()
|
||||
{
|
||||
var baz = typeof (Baz).ToDefinition ();
|
||||
var baz_dofoo = baz.GetMethod ("DoFoo");
|
||||
|
||||
var @base = baz_dofoo.GetBaseMethod ();
|
||||
Assert.AreEqual ("Bar", @base.DeclaringType.Name);
|
||||
|
||||
@base = @base.GetBaseMethod ();
|
||||
Assert.AreEqual ("Foo", @base.DeclaringType.Name);
|
||||
|
||||
Assert.AreEqual (@base, @base.GetBaseMethod ());
|
||||
|
||||
var new_dobar = baz.GetMethod ("DoBar");
|
||||
@base = new_dobar.GetBaseMethod();
|
||||
Assert.AreEqual("Baz", @base.DeclaringType.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOriginalBaseMethod ()
|
||||
{
|
||||
var baz = typeof (Baz).ToDefinition ();
|
||||
var baz_dofoo = baz.GetMethod ("DoFoo");
|
||||
|
||||
var @base = baz_dofoo.GetOriginalBaseMethod ();
|
||||
Assert.AreEqual ("Foo", @base.DeclaringType.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/ModuleDefinitionRocksTests.cs
vendored
Normal file
29
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/ModuleDefinitionRocksTests.cs
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Linq;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
namespace Mono.Cecil.Tests {
|
||||
|
||||
[TestFixture]
|
||||
public class ModuleDefinitionRocksTests : BaseTestFixture {
|
||||
|
||||
[Test]
|
||||
public void GetAllTypesTest ()
|
||||
{
|
||||
TestCSharp ("Types.cs", module => {
|
||||
var sequence = new [] {
|
||||
module.GetType ("<Module>"),
|
||||
module.GetType ("Foo"),
|
||||
module.GetType ("Foo/Bar"),
|
||||
module.GetType ("Foo/Gazonk"),
|
||||
module.GetType ("Foo/Gazonk/Baz"),
|
||||
module.GetType ("Pan"),
|
||||
};
|
||||
|
||||
Assert.IsTrue (sequence.SequenceEqual (module.GetAllTypes ()));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
67
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/SecurityDeclarationRocksTests.cs
vendored
Normal file
67
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/SecurityDeclarationRocksTests.cs
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Security.Permissions;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
namespace Mono.Cecil.Tests {
|
||||
|
||||
[TestFixture]
|
||||
public class SecurityDeclarationRocksTests : BaseTestFixture {
|
||||
|
||||
[Test]
|
||||
public void ToPermissionSetFromPermissionSetAttribute ()
|
||||
{
|
||||
TestModule ("decsec-xml.dll", module => {
|
||||
var type = module.GetType ("SubLibrary");
|
||||
|
||||
Assert.IsTrue (type.HasSecurityDeclarations);
|
||||
Assert.AreEqual (1, type.SecurityDeclarations.Count);
|
||||
|
||||
var declaration = type.SecurityDeclarations [0];
|
||||
|
||||
var permission_set = declaration.ToPermissionSet ();
|
||||
|
||||
Assert.IsNotNull (permission_set);
|
||||
|
||||
string permission_set_value = "<PermissionSet class=\"System.Security.PermissionSe"
|
||||
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"{0}\"\r\nversion=\"1\"\r\nFla"
|
||||
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n";
|
||||
|
||||
permission_set_value = string.Format (permission_set_value, typeof (SecurityPermission).AssemblyQualifiedName);
|
||||
|
||||
Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ()));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToPermissionSetFromSecurityAttribute ()
|
||||
{
|
||||
TestModule ("decsec-att.dll", module => {
|
||||
var type = module.GetType ("SubLibrary");
|
||||
|
||||
Assert.IsTrue (type.HasSecurityDeclarations);
|
||||
Assert.AreEqual (1, type.SecurityDeclarations.Count);
|
||||
|
||||
var declaration = type.SecurityDeclarations [0];
|
||||
|
||||
var permission_set = declaration.ToPermissionSet ();
|
||||
|
||||
Assert.IsNotNull (permission_set);
|
||||
|
||||
string permission_set_value = "<PermissionSet class=\"System.Security.PermissionSe"
|
||||
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"{0}\"\r\nversion=\"1\"\r\nFla"
|
||||
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n";
|
||||
|
||||
permission_set_value = string.Format (permission_set_value, typeof (SecurityPermission).AssemblyQualifiedName);
|
||||
|
||||
Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ()));
|
||||
});
|
||||
}
|
||||
|
||||
static string Normalize (string s)
|
||||
{
|
||||
return s.Replace ("\n", "").Replace ("\r", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
97
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/TypeDefinitionRocksTests.cs
vendored
Normal file
97
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/TypeDefinitionRocksTests.cs
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Mono.Cecil.Tests {
|
||||
|
||||
[TestFixture]
|
||||
public class TypeDefinitionRocksTests {
|
||||
|
||||
class Foo {
|
||||
|
||||
static Foo ()
|
||||
{
|
||||
}
|
||||
|
||||
public Foo (int a)
|
||||
{
|
||||
}
|
||||
|
||||
public Foo (int a, string s)
|
||||
{
|
||||
}
|
||||
|
||||
public static void Bar ()
|
||||
{
|
||||
}
|
||||
|
||||
void Baz ()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetConstructors ()
|
||||
{
|
||||
var foo = typeof (Foo).ToDefinition ();
|
||||
var ctors = foo.GetConstructors ().Select (ctor => ctor.FullName);
|
||||
|
||||
var expected = new [] {
|
||||
"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.cctor()",
|
||||
"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.ctor(System.Int32)",
|
||||
"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.ctor(System.Int32,System.String)",
|
||||
};
|
||||
|
||||
AssertSet (expected, ctors);
|
||||
}
|
||||
|
||||
static void AssertSet<T> (IEnumerable<T> expected, IEnumerable<T> actual)
|
||||
{
|
||||
Assert.IsFalse (expected.Except (actual).Any ());
|
||||
Assert.IsTrue (expected.Intersect (actual).SequenceEqual (expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetStaticConstructor ()
|
||||
{
|
||||
var foo = typeof (Foo).ToDefinition ();
|
||||
var cctor = foo.GetStaticConstructor ();
|
||||
|
||||
Assert.IsNotNull (cctor);
|
||||
Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.cctor()", cctor.FullName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethods ()
|
||||
{
|
||||
var foo = typeof (Foo).ToDefinition ();
|
||||
var methods = foo.GetMethods ().ToArray ();
|
||||
|
||||
Assert.AreEqual (2, methods.Length);
|
||||
Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::Bar()", methods [0].FullName);
|
||||
Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::Baz()", methods [1].FullName);
|
||||
}
|
||||
|
||||
enum Pan : byte {
|
||||
Pin,
|
||||
Pon,
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEnumUnderlyingType ()
|
||||
{
|
||||
var pan = typeof (Pan).ToDefinition ();
|
||||
|
||||
Assert.IsNotNull (pan);
|
||||
Assert.IsTrue (pan.IsEnum);
|
||||
|
||||
var underlying_type = pan.GetEnumUnderlyingType ();
|
||||
Assert.IsNotNull (underlying_type);
|
||||
|
||||
Assert.AreEqual ("System.Byte", underlying_type.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
124
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/TypeReferenceRocksTests.cs
vendored
Normal file
124
external/linker/cecil/rocks/Test/Mono.Cecil.Tests/TypeReferenceRocksTests.cs
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Mono.Cecil.Tests {
|
||||
|
||||
[TestFixture]
|
||||
public class TypeReferenceRocksTests {
|
||||
|
||||
[Test]
|
||||
public void MakeArrayType ()
|
||||
{
|
||||
var @string = GetTypeReference (typeof (string));
|
||||
|
||||
var string_array = @string.MakeArrayType ();
|
||||
|
||||
Assert.IsInstanceOf (typeof (ArrayType), string_array);
|
||||
Assert.AreEqual (1, string_array.Rank);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MakeArrayTypeRank ()
|
||||
{
|
||||
var @string = GetTypeReference (typeof (string));
|
||||
|
||||
var string_array = @string.MakeArrayType (3);
|
||||
|
||||
Assert.IsInstanceOf (typeof (ArrayType), string_array);
|
||||
Assert.AreEqual (3, string_array.Rank);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MakePointerType ()
|
||||
{
|
||||
var @string = GetTypeReference (typeof (string));
|
||||
|
||||
var string_ptr = @string.MakePointerType ();
|
||||
|
||||
Assert.IsInstanceOf (typeof (PointerType), string_ptr);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MakeByReferenceType ()
|
||||
{
|
||||
var @string = GetTypeReference (typeof (string));
|
||||
|
||||
var string_byref = @string.MakeByReferenceType ();
|
||||
|
||||
Assert.IsInstanceOf (typeof (ByReferenceType), string_byref);
|
||||
}
|
||||
|
||||
class OptionalModifier {}
|
||||
|
||||
[Test]
|
||||
public void MakeOptionalModifierType ()
|
||||
{
|
||||
var @string = GetTypeReference (typeof (string));
|
||||
var modopt = GetTypeReference (typeof (OptionalModifier));
|
||||
|
||||
var string_modopt = @string.MakeOptionalModifierType (modopt);
|
||||
|
||||
Assert.IsInstanceOf (typeof (OptionalModifierType), string_modopt);
|
||||
Assert.AreEqual (modopt, string_modopt.ModifierType);
|
||||
}
|
||||
|
||||
class RequiredModifier { }
|
||||
|
||||
[Test]
|
||||
public void MakeRequiredModifierType ()
|
||||
{
|
||||
var @string = GetTypeReference (typeof (string));
|
||||
var modreq = GetTypeReference (typeof (RequiredModifierType));
|
||||
|
||||
var string_modreq = @string.MakeRequiredModifierType (modreq);
|
||||
|
||||
Assert.IsInstanceOf (typeof (RequiredModifierType), string_modreq);
|
||||
Assert.AreEqual (modreq, string_modreq.ModifierType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MakePinnedType ()
|
||||
{
|
||||
var byte_array = GetTypeReference (typeof (byte []));
|
||||
|
||||
var pinned_byte_array = byte_array.MakePinnedType ();
|
||||
|
||||
Assert.IsInstanceOf (typeof (PinnedType), pinned_byte_array);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MakeSentinelType ()
|
||||
{
|
||||
var @string = GetTypeReference (typeof (string));
|
||||
|
||||
var string_sentinel = @string.MakeSentinelType ();
|
||||
|
||||
Assert.IsInstanceOf (typeof (SentinelType), string_sentinel);
|
||||
}
|
||||
|
||||
class Foo<T1, T2> {}
|
||||
|
||||
[Test]
|
||||
public void MakeGenericInstanceType ()
|
||||
{
|
||||
var foo = GetTypeReference (typeof (Foo<,>));
|
||||
var @string = GetTypeReference (typeof (string));
|
||||
var @int = GetTypeReference (typeof (int));
|
||||
|
||||
var foo_string_int = foo.MakeGenericInstanceType (@string, @int);
|
||||
|
||||
Assert.IsInstanceOf (typeof (GenericInstanceType), foo_string_int);
|
||||
Assert.AreEqual (2, foo_string_int.GenericArguments.Count);
|
||||
Assert.AreEqual (@string, foo_string_int.GenericArguments [0]);
|
||||
Assert.AreEqual (@int, foo_string_int.GenericArguments [1]);
|
||||
}
|
||||
|
||||
static TypeReference GetTypeReference (Type type)
|
||||
{
|
||||
return ModuleDefinition.ReadModule (typeof (TypeReferenceRocksTests).Module.FullyQualifiedName).ImportReference (type);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
external/linker/cecil/rocks/Test/Resources/cs/Types.cs
vendored
Normal file
14
external/linker/cecil/rocks/Test/Resources/cs/Types.cs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
public class Foo {
|
||||
|
||||
public class Bar {
|
||||
}
|
||||
|
||||
public class Gazonk {
|
||||
|
||||
public class Baz {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Pan {
|
||||
}
|
||||
Reference in New Issue
Block a user